# Generating signed distance field for L-shape

4 views (last 30 days)
SAMUEL AYINDE on 23 Apr 2019
Signed distance field describe the closest distance to a shape from any point in the domain. For example, the code below will generate a signed distance field for a rectangular domain with holes. Can someone please help me to modify this code or write another code that can generate signed distance field for an L-shape in the attached picture. Thank you so much.
The code:
DomainWidth=2;
DomainHight=1;
ENPC=40;
ENPR=80;
EW = DomainWidth / ENPR; % The width of each finite element.
EH = DomainHight / ENPC; % The hight of each finite element.
M = [ ENPC + 1 , ENPR + 1 ];
[ x ,y ] = meshgrid( EW * [0: ENPR] , EH * [ 0 : ENPC]);
LS.x = x(:); LS.y = y(:); % The coordinates of each Level Set grid
cx = DomainWidth / 200 * [ 0 0 0 33.33 33.33 33.33 66.67 66.67 66.67 100 100 100 133.33 133.33 133.33 166.67 166.67 166.67 200 200 200];
cy = DomainHight / 100 * [ 25 50 75 25 50 75 25 50 75 25 50 75 25 50 75 25 50 75 25 50 75];
for i = 1 : length( cx )
tmpPhi( :, i ) = - sqrt ( ( LS . x - cx ( i ) ) .^2 + ( LS . y - cy ( i ) ) .^2 ) + DomainHight/15;
end
Phi1 = -(max(tmpPhi.')).';
Phi = Phi1;
save('Phi1.mat','Phi1')
LS.Phi = griddata( LS.x, LS.y, Phi, LS.x, LS.y, 'cubic');
figure(11)
LS.Phi1 = Phi1;
figure(11)
subplot(2,1,1)
contourf( reshape( LS.x, M), reshape(LS.y , M), reshape(LS.Phi, M));axis equal;grid on;title('initialization');
subplot(2,1,2)
contourf( reshape( LS.x, M), reshape(LS.y , M), reshape(LS.Phi1, M), [0 0]);axis equal;grid on;title('initialization');hold on;

### Categories

Find more on Contour Plots in Help Center and File Exchange

R2018b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!