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

14 visualizaciones (últimos 30 días)
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-');

Respuestas (1)

Misun Kim
Misun Kim el 8 de Mayo de 2020
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);

Categorías

Más información sobre Voronoi Diagram en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by