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 CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by