3
$\begingroup$

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]]  

enter image description here

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

enter image description here

$\endgroup$
5
$\begingroup$
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[]}] 

enter image description here

Replace pts[] with pts[10] to get

enter image description here

$\endgroup$
3
$\begingroup$

With your polygon being:

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
 ]

enter image description here


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
 ]

enter image description here


EDIT-2

To get points on the boundary (choose resolution):

dreg = DiscretizeRegion[regP, MaxCellMeasure -> 0.05]

enter image description here

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
 ]

enter image description here

$\endgroup$
3
  • $\begingroup$ why there are not point on the borderline? $\endgroup$ Jan 6 at 9:29
  • $\begingroup$ 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? $\endgroup$
    – Syed
    Jan 6 at 9:31
  • 1
    $\begingroup$ @valarmorghulis I have added another strategy. $\endgroup$
    – Syed
    Jan 6 at 9:52
2
$\begingroup$

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]

enter image description here

$\endgroup$
1
$\begingroup$
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]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.