pointSetDistMap
Below is a basic demonstration of the features of the pointSetDistMap function.
Contents
clear all; close all; clc; % PLOT SETTINGS fig_color='w'; fig_colordef='white'; markerSize1=10; markerSize2=15; lineWidth=2; fontSize=20; faceAlpha=0.8;
DEFORMING A 2D MESH
SIMULATING A 2D EXAMPLE
interpMethod='cubic'; closeLoopOpt=1; n=200; %P1 t=linspace(0,2*pi,n); t=t(1:end-1); r=ones(size(t)); [x,y] = pol2cart(t,r); P1=[x(:) y(:)]; [P1]=evenlySampleCurve(P1,n,interpMethod,closeLoopOpt); %P2 t=linspace(0,2*pi,n); t=t(1:end-1); r=1+0.3*sin(3*t); [x,y] = pol2cart(t,r); P2=[x(:) y(:)]; [P2]=evenlySampleCurve(P2,n,interpMethod,closeLoopOpt); %P1i np=50; [x,y]=meshgrid(linspace(-1,1,np)); P1i=zeros(numel(x(:)),2); P1i(:,1)=x(:); P1i(:,2)=y(:); [IN,~] = inpolygon(P1i(:,1),P1i(:,2),P1(:,1),P1(:,2)); P1i=P1i(IN(:),:); P1i=[P1i; P1]; P1i=unique(P1i,'rows'); DT = delaunayTriangulation(P1i(:,[1 2])); %P2i Fw=5; [P2i]=pointSetDistMap(P1,P1i,P2,Fw);
Warning: INTERP1(...,'CUBIC') will change in a future release. Use INTERP1(...,'PCHIP') instead. Warning: INTERP1(...,'CUBIC') will change in a future release. Use INTERP1(...,'PCHIP') instead. Warning: INTERP1(...,'CUBIC') will change in a future release. Use INTERP1(...,'PCHIP') instead. Warning: INTERP1(...,'CUBIC') will change in a future release. Use INTERP1(...,'PCHIP') instead.
PLOTTING RESULTS: Circles are boundary points which should be mapped exactly. Blue points are the initial and mapped points. Tesselation shows connectivity (which may become distorted)
hf1=figuremax(fig_color,fig_colordef); subplot(1,2,1); hold on; title('Initial','FontSize',fontSize); patch('faces',DT.ConnectivityList,'Vertices',P1i,'FaceColor','g','FaceAlpha',faceAlpha); plot(P1(:,1),P1(:,2),'ko-','MarkerSize',markerSize1); plot(P1i(:,1),P1i(:,2),'b.','MarkerSize',markerSize2); set(gca,'FontSize',fontSize); view(2); grid on; axis equal; axis tight; subplot(1,2,2); hold on; title('Deformed','FontSize',fontSize); patch('faces',DT.ConnectivityList,'Vertices',P2i,'FaceColor','r','FaceAlpha',faceAlpha); plot(P2(:,1),P2(:,2),'ko-','MarkerSize',markerSize1); plot(P2i(:,1),P2i(:,2),'b.','MarkerSize',markerSize2); set(gca,'FontSize',fontSize); view(2); grid on; axis equal; axis tight; drawnow;

DEFORMING A 3D MESH
SIMULATING A 3D EXAMPLE
%P1 [F,P1,~]=geoSphere(3,1); %P1i np=15; [x,y,z]=meshgrid(linspace(-1,1,np)); P1i=[x(:) y(:) z(:)]; DT = delaunayTriangulation(P1); LI = ~isnan(pointLocation(DT,P1i)); P1i=[P1; P1i(LI,:)]; P1i=unique(P1i,'rows'); DT = delaunayTriangulation(P1i(:,[1 2])); %P2 [PHI,THETA,R] = cart2sph(P1(:,1),P1(:,2),P1(:,3)); R=1+0.3*sin(3*PHI); P2=P1; [P2(:,1),P2(:,2),~]=sph2cart(PHI,THETA,R); %P2i Fw=5; [P2i]=pointSetDistMap(P1,P1i,P2,Fw);
Warning: Duplicate data points have been detected and removed. The Triangulation indices are defined with respect to the unique set of points in delaunayTriangulation property X.
PLOTTING RESULTS: Circles are boundary points which should be mapped exactly. Blue points are the initial and mapped points. Tesselation shows connectivity (which may become distorted)
hf2=figuremax(fig_color,fig_colordef); subplot(1,2,1); hold on; title('Initial','FontSize',fontSize); patch('faces',F,'Vertices',P1,'FaceColor','g','FaceAlpha',faceAlpha); plot3(P1(:,1),P1(:,2),P1(:,3),'ko','MarkerSize',markerSize1); plot3(P1i(:,1),P1i(:,2),P1i(:,3),'b.','MarkerSize',markerSize2); set(gca,'FontSize',fontSize); camlight('headlight'); view(3); grid on; axis equal; axis tight; subplot(1,2,2); hold on; title('Deformed','FontSize',fontSize); patch('faces',F,'Vertices',P2,'FaceColor','r','FaceAlpha',faceAlpha); plot3(P2(:,1),P2(:,2),P2(:,3),'ko','MarkerSize',markerSize1); plot3(P2i(:,1),P2i(:,2),P2i(:,3),'b.','MarkerSize',markerSize2); set(gca,'FontSize',fontSize); camlight('headlight'); view(3); grid on; axis equal; axis tight; drawnow; %Create tesselations for vizualisation V1=[P1; P1i]; V2=[P2; P2i]; [~,ind1,ind2]=unique(V1,'rows'); %remove double points V1=V1(ind1,:); V2=V2(ind1,:); DT1 = delaunayTriangulation(V1); TET=DT1.ConnectivityList; %Create cut Z=V1(:,3); Ztet=mean(Z(TET),2); Ltet=(Ztet<0); %Convert elements of interest to patchable faces [Ft,~]=element2patch(TET(Ltet,:),1:size(TET(Ltet,:),1)); %Only plot outer faces %Get face counts Fs=sort(Ft,2); %Sort so faces with same nodes have the same rows [~,IND_F,IND_F_2]=unique(Fs,'rows'); F_uni=Ft(IND_F,:); numF=size(Fs,1); numFuni=size(F_uni,1); logicColourMatrixEntry=sparse(IND_F_2,1:numF,1,numFuni,numF,numF); F_count=full(sum(logicColourMatrixEntry,2)); Ftu=F_uni(F_count==1,:); %Get outer surfaces hf3=figuremax(fig_color,fig_colordef); subplot(1,2,1); hold on; title('Initial','FontSize',fontSize); patch('faces',Ftu,'Vertices',V1,'FaceColor','g'); set(gca,'FontSize',fontSize); camlight('headlight'); view(3); grid on; axis equal; axis tight; subplot(1,2,2); hold on; title('Deformed','FontSize',fontSize); patch('faces',Ftu,'Vertices',V2,'FaceColor','r'); set(gca,'FontSize',fontSize); camlight('headlight'); view(3); grid on; axis equal; axis tight; drawnow;


GIBBON
Kevin M. Moerman (kevinmoerman@hotmail.com)