How to generate points in triangular lattice pattern

9 ビュー (過去 30 日間)
Robin
Robin 2019 年 7 月 31 日
コメント済み: Parikshit Vyas 2023 年 2 月 5 日
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 Center および File ExchangeAgriculture についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by