function [ p, t ] = distmesh_3d ( fd, fh, h0, box, iteration_max, pfix, varargin ) %*****************************************************************************80 % %% DISTMESH_3D 3D Mesh Generator using Distance Functions. % % Copyright: % % (C) 2004 Per-Olof Persson. % See COPYRIGHT.TXT for details. % % Modified: % % 19 September 2005 % % Reference: % % Per-Olof Persson and Gilbert Strang, % A Simple Mesh Generator in MATLAB, % SIAM Review, % Volume 46, Number 2, June 2004, pages 329-345. % % Parameters: % % Input, function FD, signed distance function d(x,y). % % Input, function FH, scaled edge length function h(x,y). % % Input, real H0, the initial smallest edge length. % % Input, real BOX(3,2), a bounding box for the region. % % 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. % % Input, real PFIX(NFIX,3), the coordinates of nodes that are % required to be included in the mesh. % % Input, VARARGIN, additional parameters that can be passed to FD % % Output, real P(N,3), node coordinates. % % Output, integer T(NT,4), tetrahedron indices. % dim = 3; ptol = 0.001; ttol = 0.1; L0mult = 1 + 0.4 / 2^(dim-1); deltat = 0.1; geps = 0.1 * h0; deps = sqrt ( eps ) * h0; iteration = 0; % % 1. Create the initial distribution in the bounding box. % cbox = cell(1,dim); for ii = 1 : dim cbox{ii} = box(1,ii) : h0 : box(2,ii); end pp = cell(1,dim); [pp{:}] = ndgrid(cbox{:}); p = zeros(prod(size(pp{1})),dim); for ii = 1 : dim p(:,ii) = pp{ii}(:); end % % 2. Remove points outside the region, apply the rejection method. % p = p ( feval(fd,p,varargin{:}) < geps, : ); r0 = feval ( fh, p ); p = p(rand(size(p,1),1)