How to distribute points uniformly through the grid of multiple hexagons?
10 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 1 Feb 2020
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.
Accepted Answer
Jan
on 12 Jan 2018
Edited: Jan
on 12 Jan 2018
You can do this for each hexagon:
- Get the coordinates of the surrounding square (not rectangle) with the side length L.
- Choose coordinates randomly using L * rand(1, 2) and reject points, which are outside the hexagon. If the point is inside, store the coordinates.
- Proceed with step 2. until you have the wanted number of points.
Two examples for code:
- In a 3D shape: https://www.mathworks.com/matlabcentral/answers/353266-how-to-generate-100-random-points-inside-the-figure#answer_278594
- In 2D considering a minimal distance: https://www.mathworks.com/matlabcentral/answers/322431-randompoints-condition-distance.
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 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots 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!