Skip to main content
added 8 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
  • We can also extend the edges of the convex polygon at first.
  • We can also extend the edges of the convex at first.
  • We can also extend the edges of the convex polygon at first.
deleted 93 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Clear["Global`*"];
SeedRandom[1234];
k = 5;
n = 2 k;
poly = RandomPolygon[{"Convex", k}];
lines = MeshPrimitives[poly, 1];
extendLines = 
  lines /. Line[{a_, b_}] :> 
    Line[{a, b + RandomReal[{.4, .6}]*(b - a)}];
polys0 = 
  Partition[extendLines, 2, 1, 
    1] /. {Line[{a_, b_}], Line[{c_, d_}]} :> 
    Polygon[{c, b, b + d - c, d}];
pairs = Partition[extendLines, 2, 1, 
    1] /. {Line[{a_, b_}], Line[{c_, d_}]} :> Point[{b, b + d - c, d}];
countAngles[pts_] := 
  Table[PlanarAngle[{pts[[Mod[i - 1, Length@ptsThread[PlanarAngle[#, 1]]],"Counterclockwise"] 
 & /@  
    pts[[Mod[i, Length@ptsPartition[pts, 1]]]3, pts[[Mod[i + 1, Length@pts, 1]]]{2},
      "Counterclockwise"]] > π, {i, 1, Length@pts}];π];
test[pts_] := And @@ countAngles[pts];
extend[pts_] := Module[{n, pos, p, poly, a, b, c, d}, n = Length@pts;
   pos = First@FirstPosition[countAngles@pts, False];
   a = pts[[Mod[pos - 1, n, 1]]];
   b = pts[[pos]];
   c = pts[[Mod[pos + 1, n, 1]]];
   d = a + c - b;
   Sow[Polygon[{a, b, c, d}]];
   ReplacePart[pts, pos -> d]];
pts = Flatten[pairs[[;; , 1]][[;; , 1 ;; 2]], 1];
result = Reap@NestWhileList[extend, pts, Not@*test]; 
g = Graphics[{LightYellow, 
   poly, {EdgeForm[Black], FaceForm[LightBlue], polys0}, {FaceForm[Orange], EdgeForm[Black], #} & /@ 
    First@result[[2]]}]
Clear["Global`*"];
SeedRandom[1234];
k = 5;
n = 2 k;
poly = RandomPolygon[{"Convex", k}];
lines = MeshPrimitives[poly, 1];
extendLines = 
  lines /. Line[{a_, b_}] :> 
    Line[{a, b + RandomReal[{.4, .6}]*(b - a)}];
polys0 = 
  Partition[extendLines, 2, 1, 
    1] /. {Line[{a_, b_}], Line[{c_, d_}]} :> 
    Polygon[{c, b, b + d - c, d}];
pairs = Partition[extendLines, 2, 1, 
    1] /. {Line[{a_, b_}], Line[{c_, d_}]} :> Point[{b, b + d - c, d}];
countAngles[pts_] := 
  Table[PlanarAngle[{pts[[Mod[i - 1, Length@pts, 1]]], 
       pts[[Mod[i, Length@pts, 1]]], pts[[Mod[i + 1, Length@pts, 1]]]},
      "Counterclockwise"] > π, {i, 1, Length@pts}];
test[pts_] := And @@ countAngles[pts];
extend[pts_] := Module[{n, pos, p, poly, a, b, c, d}, n = Length@pts;
   pos = First@FirstPosition[countAngles@pts, False];
   a = pts[[Mod[pos - 1, n, 1]]];
   b = pts[[pos]];
   c = pts[[Mod[pos + 1, n, 1]]];
   d = a + c - b;
   Sow[Polygon[{a, b, c, d}]];
   ReplacePart[pts, pos -> d]];
pts = Flatten[pairs[[;; , 1]][[;; , 1 ;; 2]], 1];
result = Reap@NestWhileList[extend, pts, Not@*test]; 
g = Graphics[{LightYellow, 
   poly, {EdgeForm[Black], FaceForm[LightBlue], polys0}, {FaceForm[Orange], EdgeForm[Black], #} & /@ 
    First@result[[2]]}]
Clear["Global`*"];
SeedRandom[1234];
k = 5;
n = 2 k;
poly = RandomPolygon[{"Convex", k}];
lines = MeshPrimitives[poly, 1];
extendLines = 
  lines /. Line[{a_, b_}] :> 
    Line[{a, b + RandomReal[{.4, .6}]*(b - a)}];
polys0 = 
  Partition[extendLines, 2, 1, 
    1] /. {Line[{a_, b_}], Line[{c_, d_}]} :> 
    Polygon[{c, b, b + d - c, d}];
pairs = Partition[extendLines, 2, 1, 
    1] /. {Line[{a_, b_}], Line[{c_, d_}]} :> Point[{b, b + d - c, d}];
countAngles[pts_] := 
  Thread[PlanarAngle[#, "Counterclockwise"] & /@  
     Partition[pts, 3, 1, {2}] > π];
test[pts_] := And @@ countAngles[pts];
extend[pts_] := Module[{n, pos, p, poly, a, b, c, d}, n = Length@pts;
   pos = First@FirstPosition[countAngles@pts, False];
   a = pts[[Mod[pos - 1, n, 1]]];
   b = pts[[pos]];
   c = pts[[Mod[pos + 1, n, 1]]];
   d = a + c - b;
   Sow[Polygon[{a, b, c, d}]];
   ReplacePart[pts, pos -> d]];
pts = Flatten[pairs[[;; , 1]][[;; , 1 ;; 2]], 1];
result = Reap@NestWhileList[extend, pts, Not@*test]; 
g = Graphics[{LightYellow, 
   poly, {EdgeForm[Black], FaceForm[LightBlue], polys0}, {FaceForm[Orange], EdgeForm[Black], #} & /@ 
    First@result[[2]]}]
edited body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
  • When the Counterclockwise angle lestless then π, we extrudeextend one parallelogram, until the outer polygon become a n=2k sides convex polygon.
  • When the Counterclockwise angle lest then π, we extrude one parallelogram until the outer polygon become a n=2k sides convex polygon.
  • When the Counterclockwise angle less then π, we extend one parallelogram, until the outer polygon become a n=2k sides convex polygon.
added 1 character in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
deleted 28 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 1421 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 1421 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 599 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 93 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 4 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 523 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 1 character in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
added 133 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
deleted 2 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
Loading