Mathematica Asked on September 3, 2021
How could I generate these points
hexagon={{0, Sqrt[3]/2}, {1/2, Sqrt[3]}, {3/2, Sqrt[3]}, {2, Sqrt[3]/2}, {3/2,
0}, {1/2, 0}}
following this rule
pts[x_, y_] := Flatten[Table[{{3 j, Sqrt[3] k}}, {j, 1, x}, {k, 0, y}], 2]];
but inside this region
ConvexHullMesh[{t1, t2, t1 + t2, {0, 0}}]
where
m = 1.;
n = m + 1;
a1 = {Sqrt[3]/2, -1/2}*Sqrt[3];
a2 = {Sqrt[3]/2, 1/2}*Sqrt[3];
t1 = m*a1 + n*a2;
t2 = (n + m)*a1 - m*a2;
I tried to use something like this
totalpoints=TranslationTransform[# - hexagon[[1]]][hexagon] & /@
pts[somesize, somesize];
And then I cut inside the region doing this
pointsinsideregion =
Table[If[RegionMember[
ConvexHullMesh[{t1, t2, t1 + t2, {0, 0}}], totalpoints[[u]]],
totalpoints[[u]], Nothing], {u, 1, totalpoints[Upp]}]
The problem is that I use more points that is necessary (in function pts[x,y] where somesize i get usually in terms of "m") to the calculation.
Maybe the solution is something using regionmember with the function pts[x,y]
.
.
.
Just to illustrate
eta = Graphics[{EdgeForm[Thickness[0.001]], PointSize[0.009], Blue,
Point /@ TranslationTransform[# - hexagon[[4]]][hexagon] & /@
pts[5, 5]}];
Show[ConvexHullMesh[{t1, t2, t1 + t2, {0, 0}} + 4 m], eta,
Frame -> True, PlotRange -> Full]
Use RegionMember
. Also consider using CirclePoints
rather than generating the hexagon coordinates manually. I've used DeleteDuplicates
to get rid of overlapping points too:
m = 1.;
n = m + 1;
a1 = {Sqrt[3]/2, -1/2}*Sqrt[3];
a2 = {Sqrt[3]/2, 1/2}*Sqrt[3];
t1 = m*a1 + n*a2;
t2 = (n + m)*a1 - m*a2;
hexagon = CirclePoints[6];
pts[x_, y_] := # + {x, y} & /@ CirclePoints[6]
reg = ConvexHullMesh[{t1, t2, t1 + t2, {0, 0}}];
lattice =
DeleteDuplicates@
Flatten[Table[
pts[3 x/2, Sqrt[3] y + 3 Sqrt[3]/2 x], {x, -1, 5}, {y, -10, 0}],
2];
inside = Select[lattice, RegionMember[reg, #] &];
Graphics[{Gray, reg, Red,
Point[lattice],
Blue, Point[inside]
}, Frame -> True, PlotRange -> {{-1, 8}, {-5, 4}}]
Answered by flinty on September 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP