2013-04-24 138 views
1

我正在使用Delaunay三角剖分法将多边形拆分为三角形。我使用大码处理有限元,我的一个“检查点”是对称的(如果数据是对称的,输出也必须是对称的)。但是,由于我无法控制Delaunay三角剖分,所以我失去了对称性。Delaunay三角剖分使我失去对称性

我写了一个小代码来说明我的问题:我们考虑两个不相交的三角形和一个与它们相交的大矩形。我们希望与三角矩形这些三角形的减法:

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; 

delaunay triangulation

正如你所看到的,Delaunay三角不必在两个三角形相同的行为,对称的,因此损失。

有没有简单的方法来恢复对称性?

我使用Matlab R2013a。

+0

我决定为他人添加另一个答案,以查看两个结果作为参考。 – anandr 2013-04-26 14:59:50

回答

0

好像你使用的是MatLab R2013,因为在我的R2011b中没有delaunayTriangulation函数。为了能够运行你的代码我改变了它稍微:

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) 

    % This is triangulation of subtraction 
    DT = delaunay(x3,y3); 
    triplot(DT,x3,y3, 'Marker','.', 'Color','r') 

    % This is triangulation of intersection 
    DT = delaunay(x2,y2); 
    triplot(DT,x2,y2, 'Marker','o', 'Color','b', 'LineWidth',1) 

end 
axis equal; 
axis tight; 
box on; 

XL = xlim; xlim(XL+[-1 +1]*diff(XL)/10); 
YL = ylim; ylim(YL+[-1 +1]*diff(YL)/10); 

text(0.5,0.55,'triangulation of subtraction', 'HorizontalAlignment','center', 'VerticalAlignment','bottom', 'Color','r'); 
text(0.5,0.45,'triangulation of intersection', 'HorizontalAlignment','center', 'VerticalAlignment','top', 'Color','b'); 

下面是结果我看到

enter image description here

是否与你相似? 你可以在你的问题中添加一张图片来描述你得到的结果有什么问题吗?

+0

感谢您的帮助。 查看编辑的第一封邮件。 我使用'delaunayTriangulation'函数,因为在执行三角测量时(使用'delaunayTriangulation'或简单地'delaunay'),它可能导致几何体外的三角形(我们现在无法在您的图上看到它,因为交叉点的图在减法图之后;尝试仅绘制代码中的第一个“DT”,您会看到它)。出于这个原因,我使用具有边界约束的'delaunayTriangulation'函数,然后使用'isInterior'函数仅保留几何体内的三角形。 – Rambaldi 2013-04-25 19:01:21

+0

其次,奇怪的是你的代码给了我不同的结果,类似于我自己的代码的结果(在消息#1中)。 – Rambaldi 2013-04-25 19:02:41

+0

是的,我已经看到了蓝色三角形下的红色三角形。我带了更新的代码,并将其更改为使用'delaunayTri'(R2011b中的'delaunayTriangulation'的前身)。但我看到和以前一样的结果,不像你的结果。根据http://www.mathworks.com/help/matlab/release-notes.html,“delaunayTriangulation”类出现在R2013a中。那么他们是否也会改变它背后的东西?或者这是一个错误:/ – anandr 2013-04-26 14:15:26

0

看来这不是一个错误。 实际上,您的结果来自您的数据。

我打得有点与您的代码

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 

    % This is for R2013a 
    %DT = delaunayTriangulation(x3,y3); 
    %triplot(DT,'Marker','o'); 

    % This is for R2011b 
    %DT = DelaunayTri(x3,y3); 
    %triplot(DT,'Marker','o'); 

    % This is plain delaunay version 
    DT = delaunay(x3,y3); 
    triplot(DT,x3,y3,'Marker','o') 

    % we break here to analyze the first triangulation 
    break 

end 
XL = xlim; xlim(XL+[-1 +1]*diff(XL)/10); 
YL = ylim; ylim(YL+[-1 +1]*diff(YL)/10); 
axis equal; 
box on; 

% % % % % % % % % % % % % % % % % % 
% Checking the triangulation 
% % % % % % % % % % % % % % % % % % 

% Wrong triangulation for i=2 is hard-coded 
DT2  = [ 
    2 1 6 
    6 5 2 
    5 3 2 
    5 4 3 
    2 3 1 ]; 

figure; 
hold all; 
triplot(DT2,x3,y3,'Marker','o', 'Color','r', 'LineWidth',1) 
axis equal; 
axis tight; 
box on; 
XL = xlim; xlim(XL+[-1 +1]*diff(XL)*0.5); 
YL = ylim; ylim(YL+[-1 +1]*diff(YL)*0.5); 

% circumcircle: http://www.mathworks.com/matlabcentral/fileexchange/17300 
ca = linspace(0,2*pi); 
cx = cos(ca); 
cy = sin(ca); 

hl = []; 
for k=1:size(DT2,1) 
    tx = x3(DT(k,:)); 
    ty = y3(DT(k,:)); 
    [r,cn]=circumcircle([tx,ty]',0); 
    if ~isempty(hl) 
     %delete(hl); 
    end 
    fprintf('Circle %d: Center at (%.23f,%.23f); R=%.23f\n',k,cn,r); 
    text(cn(1),cn(2), sprintf('c%d',k)); 
    hl = plot(cx*r+cn(1), r*cy+cn(2), 'm-'); 
    drawnow; 
    %pause(3); %if you prefere to go slowly 
end 

这是输出我SEEE:

圈1:中心(0.28333333333333333000000,0.35000000000000003000000); R = 0.05270462766947306400000 Circle 2:Center at(0.34999999999999998000000,0.34999999999999998000000); R = 0.02357022603955168100000 Circle 3:Center at(0.28333333333333338000000,0.34999999999999992000000); R = 0.05270462766947289800000 圈4:中心在(0.35000000000000003000000,0.28333333333333355000000); R = 0.05270462766947290500000 圈5:中心在(0.35000000000000003000000,0.28333333333333333000000); R = 0.05270462766947312000000

而图:

enter image description here

所以圆圈1和3以及圆圈4和5几乎相同。 所以,你和我的结果之间的差异甚至可能来自舍入误差,因为相应的四个点在浮点数学精度内位于同一个圆上。你必须重新设计你的观点,以获得可靠的结果,而不依赖于这些事情。

玩得开心; o)

+0

好的,所以我也尝试过'DelaunayTri'函数。我给了我和以前一样的结果(带'delaunay'和'delaunayTriangulation')。 我明白你做了什么与外接的事情。但我不确定它是来自舍入误差。因为另一个三角形仍然具有良好的三角测量(“好”,我的意思是一个具有x/y对称性的三角测量)。 你认为这值得向Matlab发信号吗? – Rambaldi 2013-04-26 20:23:35

+0

我认为这种情况是四舍五入错误的结果。只需在'for i = 1:2'循环结束时在我的代码中注释'break',你会看到在另外5个圆圈(对于情况i = 2)中还有两对几乎相同的圆。此外,检查MathWorks文档可能是一个好主意,也许他们也在算法中改变了一些东西。 – anandr 2013-04-26 20:33:33

+0

我在你的代码中评论了'break',并且也相应地改变了这些圆圈的硬编码'if if == 1 DT2 = [ 2 1 6; 6 5 2; 5 3 2; 5 4 3; 2 3 1];其他 DT2 = [ 3 1 6; 4 2 3; 5 3 6; 5 4 3; 2 3 1]; end' 正如你所说,这里也有两对几乎相同的。所以现在我明白,它可能是四舍五入的错误... – Rambaldi 2013-04-26 20:59:47

相关问题