I am using Delaunay triangulation to split polygons into triangles. I work on FEM with a large code, and one of my "checkpoints" is symmetry (if the data is symmetric, the output has to be symmetric too). However, since I have no control over the Delaunay triangulation, it makes me lose the symmetry.
I have written a small code that illustrates my problem: we consider two disjoint triangles and a big rectangle that intersects them. We want to triangulate the subtractions of those triangles with the rectangle:
clear all
close all
warning off % the warning is about duplicate points, not important here
figure
hold on
p =[.3 .3
.4 .3
.3 .4
.7 .6
.6 .7
.7 .7]; % coordinates of the points for the triangles
px = 1/3;
py = 1/3;
lx = 1/3;
ly = 1/3; % size and position of the rectangle
% rearrange the polygon with clockwise-ordered vertices
[x1,y1]=poly2cw([px; px+lx; px+lx; px],[py; py; py+ly; py+ly]); % rectangle
patch(x1,y1, 1, 'EdgeColor', 'k');
for i=1:2
pc = p(3*i-2:3*i,:); % current triangle
% rearrange the polygon with clockwise-ordered vertices
[x0,y0]=poly2cw(pc(:,1),pc(:,2)); % triangle
[x2,y2] = polybool('intersection',x1,y1,x0,y0); % intersection
[x3,y3] = polybool('subtraction',x0,y0,x2,y2); % subtraction
DT = delaunayTriangulation(x3,y3);
triplot(DT,'Marker','o')
end
XL = xlim; xlim(XL+[-1 +1]*diff(XL)/10);
YL = ylim; ylim(YL+[-1 +1]*diff(YL)/10);
axis equal;
box on;
As you can see, the Delaunay triangulation does not have the same behaviour in both triangles, hence the loss of symmetry.
Is there a simple way to recover symmetry?
I use Matlab R2013a.