How to generate points to create evenly distributed equilateral triangles for the delaunayTriangulation function

조회 수: 8 (최근 30일)
This code generates the points for equilateral triangles in question for a design space 735*779~, but is inefficient, and kind of ugly. How can something like this be done better?
Bx = 720; % X Boundary
By = 360; % Y Boundary
m = 30;
x2 = 0:m:Bx; % Even row x-direction increments
x1 = m/2:m:Bx+m/2; % Odd row x-direction increments
C_X = Bx/m+1; % C_X is the number of x columns
R_X = m+1; % R_X is the number of x rows
C_Y = Bx/m+1; % C_Y is the number of y columns
R_Y = m+1; % R_Y is the number of y rows
%%%Generates Voronoi point locations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = zeros(m+1,C_X);
y = zeros(m+1,C_Y);
for i=2:2:m % Even row point locations for all y-values
x(i,:)=x2; % Original hexagonal voronoi points (1/2)
y(i,:)=ones(1,C_X)*i*sqrt(3)*(m/2)-sqrt(3)*(m/2);
end
for i=1:2:m+1 % Odd row point locations for all y-values
x(i,:)=x1; % Original hexagonal voronoi points (2/2)
y(i,:)=ones(1,C_X)*i*sqrt(3)*(m/2)-sqrt(3)*(m/2);
end
X1 = reshape(x.',1,[])'; % Converts x-matrix to an array
Y1 = reshape(y.',1,[])'; % Converts y-matrix to an array
DT = delaunayTriangulation(X1, Y1);
triplot(DT,'b-');

답변 (1개)

Misun Kim
Misun Kim 2020년 5월 8일
I had the exactly same question. I didn't find a simple solution but defining equilateral points could be simplified a bit (following the source code from this tutorial).
h0=1;
[x,y]=meshgrid(1:h0:15,1:h0*sqrt(3)/2:15);
x(2:2:end,:)=x(2:2:end,:)+h0/2; % Shift even rows
DT=delaunayTriangulation(x(:),y(:));
triplot(DT);

카테고리

Help CenterFile Exchange에서 Voronoi Diagram에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by