How to generate points in triangular lattice pattern

9 Ansichten (letzte 30 Tage)
Robin
Robin am 31 Jul. 2019
Kommentiert: Parikshit Vyas am 5 Feb. 2023
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.

Antworten (1)

Michael Madelaire
Michael Madelaire am 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 Kommentar
Parikshit Vyas
Parikshit Vyas am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Agriculture finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by