How to distribute points uniformly through the grid of multiple hexagons?

조회 수: 18 (최근 30일)
Eman S
Eman S 2018년 1월 12일
댓글: Rik 2020년 2월 2일
Hi all, I have the following code to draw hexagonal grid.
Rad3Over2 = sqrt(3) / 2;
[X Y] = meshgrid(-.2:0.2:1.6);
n = size(X,1);
X = Rad3Over2 * X;
Y = Y + repmat([0 0.5],[n,n/2]);
% Plot the hexagonal mesh, including cell borders
[XV YV] = voronoi(X(:),Y(:)); plot(XV,YV,'b-')
axis equal, axis([.2 1.2 .2 1]), zoom on
My question is:
How to distribute uniform number of points into each hexagonal (for example, 4 points into each hexagonal)?
Thanks in advance.
  댓글 수: 3
Image Analyst
Image Analyst 2020년 2월 1일
Original question (in case he changes it again):
How to distribute points uniformly through the grid of multiple hexagons?
Hi all, I have the following code to draw hexagonal grid.
Rad3Over2 = sqrt(3) / 2;
[X Y] = meshgrid(-.2:0.2:1.6);
n = size(X,1);
X = Rad3Over2 * X;
Y = Y + repmat([0 0.5],[n,n/2]);
% Plot the hexagonal mesh, including cell borders
[XV YV] = voronoi(X(:),Y(:)); plot(XV,YV,'b-')
axis equal, axis([.2 1.2 .2 1]), zoom on
My question is:
How to distribute uniform number of points into each hexagonal (for example, 4 points into each hexagonal)?
Thanks in advance.
Rik
Rik 2020년 2월 2일
@Eman, Why did you delete your comments?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 1월 12일
편집: Jan 2018년 1월 12일
You can do this for each hexagon:
  1. Get the coordinates of the surrounding square (not rectangle) with the side length L.
  2. Choose coordinates randomly using L * rand(1, 2) and reject points, which are outside the hexagon. If the point is inside, store the coordinates.
  3. Proceed with step 2. until you have the wanted number of points.
Two examples for code:
For a constructive method without rejection see John D'Errico excellent instructions: https://www.mathworks.com/matlabcentral/answers/327990-generate-random-coordinates-inside-a-convex-polytope
  댓글 수: 4
Eman S
Eman S 2018년 1월 22일
I wouldn't reject points. As shown in attached picture,in the region (1.2*1) . There are hexagons until(1.1) and halves of hexagons also. The points should distributed through the (1.2*1 region).
Jan
Jan 2018년 1월 22일
편집: Jan 2018년 1월 22일
@Eman: I do not understand your comment. What is a "1.2*1 region"? I've explained a way to create points in one hexagon. Pick each hexagon and use the suggested method to insert 4 random points. I have no idea how you want to treat the "half" hexagons.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by