%% DISTMESH_2D is a 2D mesh generator using distance functions.
% Example:
% Uniform Mesh on Unit Circle:
% fd = inline('sqrt(sum(p.^2,2))-1','p');
% [p,t] = distmesh_2d(fd,@huniform,0.2,[-1,-1;1,1],100,[]);
% Rectangle with circular hole, refined at circle boundary:
% fd = inline('ddiff(drectangle(p,-1,1,-1,1),dcircle(p,0,0,0.5))','p');
% fh = inline('min(4*sqrt(sum(p.^2,2))-1,2)','p');
% [p,t] = distmesh_2d(fd,fh,0.05,[-1,-1;1,1],500,[-1,-1;-1,1;1,-1;1,1]);
% Parameters:
% Input, function FD, signed distance function d(x,y).
% fd:d=fd(p),p=[x y],fd為給定任壹點到邊界的有符號距離函數,負號表示在區域內,正號為在區域外
% Input, function FH, scaled edge length function h(x,y).
% fh:就是網格大小的函數
% Input, real H0, the initial edge length.
% h0:也就是h, 網格的初始大小
% Input, real BOX(2,2), the bounding box [xmin,ymin; xmax,ymax].
% box:最大外圍矩形範圍
% Input, integer ITERATION_MAX, the maximum number of iterations.
% The iteration might terminate sooner than this limit, if the program decides
% that the mesh has converged.
% iteration_max:允許的最大叠代次數
% Input, real PFIX(NFIX,2), the fixed node positions.
% pfix:網格中需要固定的點坐標,也就是壹定需要出現在網格中的點
% Input, VARARGIN, aditional parameters passed to FD and FH.%
% Output, real P(N,2), the node positions.
% p:網格點的x,y坐標
% Output, integer T(NT,3), the triangle indices.
% t:輸出網格任意壹個三角形的三個頂點
% Local parameters:
% Local, real GEPS, a tolerance for determining whether a point is "almost" inside
% the region. Setting GEPS = 0 makes this an exact test. The program currently
% sets it to 0.001 * H0, that is, a very small multiple of the desired side length
% of a triangle. GEPS is also used to determine whether a triangle falls inside
% or outside the region. In this case, the test is a little tighter. The centroid
% PMID is required to satisfy FD ( PMID ) <= -GEPS.