# How can I create a mesh of closed shape?

I have this hexagon that defined according to these points

Boundrs = {{-(\[Pi]/3), -(\[Pi]/Sqrt[3])}, {-((2 \[Pi])/3),
0}, {-(\[Pi]/3), \[Pi]/Sqrt[3]}, {\[Pi]/3, \[Pi]/Sqrt[3]}, {(
2 \[Pi])/3, 0}, {\[Pi]/3, -(\[Pi]/Sqrt[3])}, {\[Pi]/
3, -(\[Pi]/Sqrt[3])}, {-(\[Pi]/3), -(\[Pi]/Sqrt[3])}};

I would like to get a regular mesh of points {xi,yi} that are only inside or at the border. I tried this

region = Polygon[Boundrs ];
points = RandomPoint[region, 900];
Show[ListLinePlot[Boundrs, PlotStyle -> Red, AspectRatio -> 1],
ListPlot[points, ImageSize -> 200]]

but it gives a random mesh, I would like to get regular mesh, something like this

pts[n_ : 30] := Select[RegionMember[Polygon @ Boundrs]][
Join @@ CoordinateBoundsArray[CoordinateBounds@Boundrs, Into[n]]];

Graphics[{FaceForm[Opacity[.7, LightOrange]], EdgeForm[{Thick, Red}],
Polygon @ Boundrs, Black, PointSize[Medium], Point @ pts[]}]

Replace pts[] with pts[10] to get

regP = Polygon[Boundrs]

Generate a grid of points according to:

{Max@#, Min@#} &@Boundrs

{(2 \[Pi])/3, -((2 \[Pi])/3)}

pts = Flatten[#, 1] &@
Table[{x, y}, {x, -2 \[Pi]/3,
2 \[Pi]/3, \[Pi]/15}, {y, -2 \[Pi]/3, 2 \[Pi]/3, \[Pi]/15}];

Find points in region:

ptsinreg = Pick[pts, (RegionMember[regP, #] & /@ pts)];

Graphics[{
Red, FaceForm[White], EdgeForm[{Thick, Red}], regP
, Blue, Point@ptsinreg
}
, Frame -> True
]

EDIT-1 Points on an angle

Define a line with a 30 degree slope

f[x_, c_] := Tan[\[Pi]/6] x + c

Generate points with different y-intercepts to cover the range.

pt00 = Flatten[#, 1] &@
Table[{x, f[x, c]}, {x, -2, 2, 0.2}, {c, -3, 3, 0.2}];

same drill:

ptsinreg = Pick[pt00, (RegionMember[regP, #] & /@ pt00)];
Graphics[{
Red, FaceForm[Nest[Lighter, Yellow, 3]], EdgeForm[{Thick, Red}], regP
, Blue, Point@ptsinreg
}
, Frame -> True
]

EDIT-2

To get points on the boundary (choose resolution):

dreg = DiscretizeRegion[regP, MaxCellMeasure -> 0.05]

pts01 = MeshCoordinates[dreg];

No need to do RegionMember this time.

Graphics[{
Red, FaceForm[Nest[Lighter, Yellow, 3]], EdgeForm[{Thick, Red}], regP
, Blue, Point@pts01
}
, Frame -> True
]

• why there are not point on the borderline? Jan 6 at 9:29
• That's a decision for RegionMember to make. I do see some, but cannot force them (or at least I don't know of a method to force the function to do it). Can you specifically say which point is missing?
– Syed
Jan 6 at 9:31
• @valarmorghulis I have added another strategy.
– Syed
Jan 6 at 9:52

Edit

To ensure that the boundary contain points,we can calculate the height of such polygon (which equal to h=π/Sqrt[3]) and divide it into n parts.

Boundrs = {{-(π/3), -(π/Sqrt[3])}, {-((2 π)/3),
0}, {-(π/3), π/Sqrt[3]}, {π/3, π/
Sqrt[3]}, {(2 π)/3,
0}, {π/3, -(π/Sqrt[3])}, {π/
3, -(π/Sqrt[3])}, {-(π/3), -(π/Sqrt[3])}};
region = Polygon[Boundrs];

h = RegionBounds[region][[2, 2]];
θ = π/6;
e1 = AngleVector[θ];
e2 = AngleVector[π - θ];
n = 8;
c = (1/n) h/Norm[e1 + e2];
pts = c*{x, y} . {e1, e2} /.
Solve[(c*{x, y} . {e1, e2}) ∈ region, {x, y}, Integers];
Graphics[{Blue, Point[pts], EdgeForm[Red], FaceForm[], region},
Axes -> True]

π/Sqrt[3]

g = Graphics[Polygon[Boundrs], ImageSize -> 50];
pos = PixelValuePositions[ColorNegate[Binarize[g]], 1];
tran = RescalingTransform[CoordinateBounds[pos],
CoordinateBounds[Boundrs]];
Graphics[{FaceForm[], EdgeForm[Blue], Polygon[Boundrs], Red,
Point[tran@pos]}]