簡體   English   中英

Delaunay三角剖分使我失去對稱性

[英]Delaunay triangulation makes me lose symmetry

我正在使用Delaunay三角剖分將多邊形拆分為三角形。 我使用大型代碼處理FEM,而我的“檢查點”之一是對稱的(如果數據是對稱的,則輸出也必須是對稱的)。 但是,由於我無法控制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三角剖分

如您所見,Delaunay三角剖分在兩個三角形中的行為不同,因此失去了對稱性。

有恢復對稱性的簡單方法嗎?

我使用Matlab R2013a。

似乎您正在使用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');

這是我看到的結果

在此處輸入圖片說明

它和你的相似嗎? 您能否在問題中添加一張圖片,說明您得到的結果出了什么問題?

看來這不是錯誤。 您的結果實際上來自您的數據。

我玩了你的代碼

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

這是我看到的輸出:

圈子1:以(0.28333333333333333000000,0.35000000000000003000000)為中心; R = 0.05270462766947306400000圓2:以(0.34999999999999998000000,0.34999999999999998000000)為中心; R = 0.02357022603955168100000第3圈:中心位於(0.28333333333333338000000,0.34999999999999992000000); R = 0.05270462766947289800000圓4:中心位於(0.35000000000000003000000,0.28333333333333355000000); R = 0.05270462766947290500000圓5:以(0.35000000000000003000000,0.28333333333333333000000)為中心; R = 0.05270462766947312000000

和圖:

在此處輸入圖片說明

因此,圓1和3以及圓4和5幾乎相同。 因此,您的結果與我的結果之間的差異甚至可能來自舍入誤差,因為相應的四個點在float數學精度內位於同一圓上。 您必須重新設計點才能獲得不依賴於此類因素的可靠結果。

玩得開心; o)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM