示例一:建立并繪制2D Delaunay三角剖分
本示例申明若何計較2D Delaunay三角剖分以及若何將三角剖分與極點和三角形標簽一路繪制。
在號令行窗口,輸入號令:
x = rand(10,1);
y = rand(10,1);
dt = delaunayTriangulation(x,y)
按“Enter鍵”。
如圖1所示。
在號令行窗口,輸入號令:
triplot(dt);
%
% Display the Vertex and Triangle labels on the plot
hold on
vxlabels = arrayfun(@(n) {sprintf('P%d', n)}, (1:10)');
Hpl = text(x, y, vxlabels, 'FontWeight', 'bold', 'HorizontalAlignment',...
'center', 'BackgroundColor', 'none');
ic = incenter(dt);
numtri = size(dt,1);
trilabels = arrayfun(@(x) {sprintf('T%d', x)}, (1:numtri)');
Htl = text(ic(:,1), ic(:,2), trilabels, 'FontWeight', 'bold', ...
'HorizontalAlignment', 'center', 'Color', 'blue');
hold off
按“Enter鍵”。
如圖2所示。
示例二:建立并繪制3D Delaunay三角剖分
本示例標的目的您展示若何計較3D Delaunay三角剖分以及若何繪制三角剖分。
在號令行窗口,輸入號令:
X = rand(10,3)
按“Enter鍵”。
如圖3所示。
在號令行窗口,輸入號令:
dt = delaunayTriangulation(X)
按“Enter鍵”。
如圖4所示。
在號令行窗口,輸入號令:
tetramesh(dt, 'FaceColor', 'cyan');
% To display large tetrahedral meshes use the convexHull method to
% compute the boundary triangulation and plot it using trisurf.
% For example;
% triboundary = convexHull(dt)
% trisurf(triboundary, X(:,1), X(:,2), X(:,3), 'FaceColor', 'cyan')
按“Enter鍵”。
如圖5所示。
示例三:拜候三角剖分數據布局
有兩種方式可以拜候三角測量數據布局。 一種方式是經由過程Triangulation屬性,另一種方式是利用索引。
從10個隨機點建立2D Delaunay三角剖分。
在號令行窗口,輸入號令:
X = rand(10,2)
按“Enter鍵”。
如圖6所示。
在號令行窗口,輸入號令:
dt = delaunayTriangulation(X)
按“Enter鍵”。
如圖7所示。
在號令行窗口,輸入號令:
% The triangulation datastructure is;
dt.ConnectivityList
按“Enter鍵”。
如圖8所示。
在號令行窗口,輸入號令:
% Indexing is a shorthand way to query the triangulation. The format is
% dt(i, j) where j is the j'th vertex of the i'th triangle, standard
% indexing rules apply.
% The triangulation datastructure is
dt(:,:)
按“Enter鍵”。
如圖9所示。
第二個三角形是;
在號令行窗口,輸入號令:
dt(2,:)
按“Enter鍵”。
如圖10所示。
第二個三角形的第三個極點是;
在號令行窗口,輸入號令:
dt(2,3)
按“Enter鍵”。
如圖11所示。
前三個三角形;
在號令行窗口,輸入號令:
dt(1:3,:)
按“Enter鍵”。
如圖12所示。
0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!