How to generate points in triangular lattice pattern

9 views (last 30 days)
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.

Answers (1)

Michael Madelaire
Michael Madelaire on 31 Jul 2019
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 Comment
Parikshit Vyas
Parikshit Vyas on 5 Feb 2023
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

Sign in to comment.

Categories

Find more on Agriculture in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!