%% =========================================================
%  网格类型演示
%  1. 结构网格（Structured Grid）
%  2. 非结构网格（Unstructured Grid）
%% =========================================================

clear; clc; close all;

%% =========================================================
% 1️⃣ 结构网格（Structured Grid）
%% =========================================================

Nx = 20;
Ny = 20;

[x, y] = meshgrid(linspace(0,1,Nx), linspace(0,1,Ny));

figure('Color','w','Position',[100 100 1200 500]);

subplot(1,2,1)

% 画网格线（核心：规则 i-j 连接）
plot(x, y, 'b', 'LineWidth',2); hold on;
plot(x', y', 'b', 'LineWidth',2);

title('Structured Grid');
axis equal;
grid on;

% 标注说明
% text(0.05, 0.9, '规则 i-j 拓扑', 'Color','r');
% text(0.05, 0.85, '每个点都有固定邻居', 'Color','r');

%% =========================================================
% 2️⃣ 非结构网格（Unstructured Grid）
%% =========================================================

% 随机点
N = 300;
px = rand(N,1);
py = rand(N,1);



% Delaunay 三角剖分
tri = delaunay(px, py);

subplot(1,2,2)

triplot(tri, px, py, 'b', 'LineWidth',2);
hold on;

title('Unstructured Grid');
axis equal;
grid on;

% 标注说明
% text(0.05, 0.9, '无规则连接', 'Color','r');
% text(0.05, 0.85, '需要 connectivity', 'Color','r');

