How to generate points in triangular lattice pattern

31 次查看(过去 30 天)
I want to generate set of points in a given region which will follow the triangular lattice pattern.The triangle formed by the points should be equilateral.

回答(1 个)

Michael Madelaire
Michael Madelaire 2019-7-31
clear all; close all; clc;
%% Triangular grid information
h_dist = 5; % Horizontal distance
v_dist = sqrt(h_dist^2-(h_dist/2)^2); % Vertical distance
%% Region size
x_lim = 100;
y_lim = 100;
%% Generate grid
trigrid = [];
y_current = 0;
xx = 0;
displacement = 0;
while y_current < y_lim
if displacement == 0
xx = [0:h_dist:x_lim]';
yy = ones(length(xx), 1)*y_current;
displacement = 1;
else
xx = [h_dist/2:h_dist:x_lim]';
yy = ones(length(xx), 1)*y_current;
displacement = 0;
end
trigrid = [trigrid; [xx,yy]];
y_current = y_current + v_dist;
end
%% Plot
figure()
plot(trigrid(:,1), trigrid(:,2), 'o', 'markersize', 2);
grid on;
xlim([-h_dist, x_lim+h_dist]);
ylim([-v_dist, y_lim+v_dist]);
  1 个评论
Parikshit Vyas
Parikshit Vyas 2023-2-5
Hi ,
Can you please explain
  • xx = [0:h_dist:x_lim]'
  • ones(length(xx), 1)
  • [trigrid; [xx,yy]]
these lines. Also if you can give python equivalent for them , it would be great.
TIA

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolating Gridded Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by