Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. Table[Polygon@Map[{Cos[#], Sin[#]} &,
  2. {RandomReal[{0, 2 Pi/3}],
  3. RandomReal[{2 Pi/3, 4 Pi/3}],
  4. RandomReal[{4 Pi/3, 2 Pi}]}], 3]
  5. Graphics[{EdgeForm[Black], White, %}]
  6.  
  7. {Polygon[{{-0.334165, 0.942514}, {-0.67166, 0.740859}, {-0.455064, -0.890459}}],
  8. Polygon[{{0.274586, 0.961563}, {-0.99882, -0.0485668}, {-0.454045, -0.890979}}],
  9. Polygon[{{0.832368, 0.554224}, {-0.977216, -0.212246}, {0.451922, -0.892057}}]}
  10.  
  11. Table[triregion[i] = BoundaryDiscretizeGraphics[Graphics[triangles[[i]]]],
  12. {i, 1, Length[triangles]}]
  13.  
  14. layerorder = {3, 2, 1}
  15.  
  16. intersections = Flatten[
  17. Table[If[Length[
  18. RegionIntersection[
  19. triregion[layerorder[[i]]],
  20. triregion[layerorder[[j]]]]
  21. ] == 0, {layerorder[[i]], layerorder[[j]]}, Nothing],
  22. {i, 1, 3}, {j, i + 1, 3}], 1]
  23.  
  24. Out: {{3, 2}, {3, 1}, {2, 1}}
  25.  
  26. Table[newregion[i] = triregion[i], {i, 20}];
  27. Map[(newregion[#[[2]]] = RegionDifference[newregion[#[[2]]], triregion[#[[1]]]]) &,
  28. intersections];
  29.  
  30. boundaries = Map[MeshPrimitives[#, 1] &, {newregion[1], newregion[2], newregion[3]}];
  31. Show[Graphics /@ boundaries]
  32.  
  33. d1 = {{-0.334165,0.942514},{-0.67166,0.740859},{-0.455064,-0.890459}};
  34. d2 = {{0.274586,0.961563},{-0.99882,-0.0485668},{-0.454045,-0.890979}};
  35. d3 = {{0.832368,0.554224},{-0.977216,-0.212246},{0.451922,-0.892057}};
  36.  
  37. t1 = Line[Append[d1, First@d1]];
  38. t2 = Line[Append[d2, First@d2]];
  39. t3 = Line[Append[d3, First@d3]];
  40.  
  41. p1 = Polygon[d1];
  42. p2 = Polygon[d2];
  43. p3 = Polygon[d3];
  44.  
  45. r1 = t3;
  46.  
  47. r2 = RegionDifference[t2, p3];
  48.  
  49. r3 = RegionDifference[t1, RegionUnion[p2, p3]];
  50.  
  51. DiscretizeRegion @ RegionUnion[r1, r2, r3]
  52.  
  53. RegionUnion[r1, r2, r3]
  54.  
  55. Region@RegionUnion[
  56. Polygon[{{-0.334165, 0.942514}, {-0.67166, 0.740859}, {-0.455064, -0.890459}}],
  57. Polygon[{{0.274586, 0.961563}, {-0.99882, -0.0485668}, {-0.454045, 0.890979}}],
  58. Polygon[{{0.832368, 0.554224}, {-0.977216, -0.212246}, {0.451922, -0.892057}}]
  59. ]
  60.  
  61. In[1]:= pols=Table[Polygon@Map[{Cos[#], Sin[#]} &, {RandomReal[{0, 2 Pi/3}],
  62. RandomReal[{2 Pi/3, 4 Pi/3}], RandomReal[{4 Pi/3, 2 Pi}]}], 3];
  63. In[2]:= Graphics[{EdgeForm[Black], White, pols}];
  64. In[3]:= DiscretizeGraphics@%;
  65. In[4]:= Graphics@MeshPrimitives[%, 1];
  66. In[5]:= reg=DiscretizeGraphics@%
  67.  
  68. In[6]:= RegionDimension@reg
  69. Out[16]= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement