3
$\begingroup$

Suppose I have Parallelogram like

Parallelogram[{1, 2}, {{3, 4}, {6, 3}}]

I can convert it into a Polygon like this

rect = Parallelogram[{1, 2}, {{6, 3}, {3, 4}}];
Graphics[{rect, Red, 
  Polygon@Append[Insert[{#, #} + #2 & @@ rect, First[rect], -2], 
    Total[Last[rect]] + First[rect]]}]

It works,but is there a better solution with based method to implement this?By the way I suprise about why MeshCoordinates[Region@Parallelogram[{1, 2}, {{6, 3}, {3, 4}}]] don't work, I don't sure it is a bug or intended..

$\endgroup$
  • $\begingroup$ Why do you need to convert it to a polygon? $\endgroup$ – Carl Woll Aug 23 '17 at 18:29
2
$\begingroup$

Let us take an example from the Help:

p = {0, 0};
v1 = {1, 2};
v2 = {1, 0};

ill = {Black, PointSize[Large], Point[p], Arrowheads[Medium], Thick, 
   Arrow[{p, v1}], Arrow[{p, v2}]};
plgm=Parallelogram[p, {v1, v2}];

and build a polygon:

pol=Polygon[{p, v1, v1 + v2, v2}];

Let we have a look:

 Row[{Graphics[{Pink, plgm, ill}, Frame -> True, ImageSize -> 200],
  Graphics[{LightBlue, pol, ill}, Frame -> True, ImageSize -> 200]}]

enter image description here

In the case of your example one needs also to add the point of origin to coordinates:

Graphics[Polygon[{{1,2}, {3, 4} + {1, 2}, {3, 4} + {6, 3} + {1, 2}, {6, 3} + {1, 2}}], 
 Axes -> True, AxesOrigin -> {0, 0}]

enter image description here

Have fun!

| improve this answer | |
$\endgroup$
  • $\begingroup$ Strick to my mind..Good example. $\endgroup$ – yode Aug 23 '17 at 16:28
  • 1
    $\begingroup$ @yode this answer does not conver given Parallelogram to Polygon so I don't understand the accept. (not that I care who gets it, just want the thread to be clear) So if you wanted a basic vector algebra lesson, you should've said so. $\endgroup$ – Kuba Aug 23 '17 at 17:01
  • $\begingroup$ @Kuba I want to do it in some basic method,so I write that complex solution in my post.And I want to know the behavior is normal or not by Region@Parallelogram[{1, 2}, {{6, 3}, {3, 4}}].I have tried your method in your answer before I post this question.I even remember BoundaryDiscretizeGraphics will not give right result, but I don't know why I cannot reproduce it now.Actually I hesitate to accept it but it make my thought more clear,and it complete 99% almost.Anyway,you make sense... $\endgroup$ – yode Aug 23 '17 at 17:47
  • 1
    $\begingroup$ @yode you are free to want whatever you want :) I just claim the accepted answer does not match the question. You can edit the quesion then. Unless I missed the point. $\endgroup$ – Kuba Aug 23 '17 at 17:54
3
$\begingroup$

Not each region is a mesh so this is the way to go:

prim = Parallelogram[{1, 2}, {{6, 3}, {3, 4}}]

MeshCoordinates @ DiscretizeGraphics @ prim

{{1., 2.}, {7., 5.}, {10., 9.}, {4., 6.}}

You can add Polygon of course. And the assumption here is that the mesh will be a single cell one. Don't know if that is a valid assumption but Parallelogram should be special for DiscretizeGraphics so I guess so.

Alternatively:

toPolygon = Apply[Polygon[{#, # + #2, +##, # + #3}] & @@ Join[{#}, #2] &];

toPolygon @ prim

Polygon[{{1, 2}, {4, 6}, {10, 9}, {7, 5}}]

| improve this answer | |
$\endgroup$
  • $\begingroup$ It is a surprise..I have ever tried MeshCoordinates@DiscretizeGraphics@prim and MeshCoordinates@DiscretizeRegion@prim,but I cannot guess MeshCoordinates @ DiscretizeGraphics @ prim as this need. But they cannot implement it. $\endgroup$ – yode Aug 23 '17 at 7:15
  • $\begingroup$ As this anser.I realize the code in above comment is a typo.So I know what you say before..Actually I want to say I have ever tried MeshCoordinates@DiscretizeRegion@prim and MeshCoordinates@BoundaryDiscretizeRegion@prim,but I cannot geuss out **Graphics something.. $\endgroup$ – yode Aug 23 '17 at 16:26
  • $\begingroup$ I eventually note this is difference when **Graphics work on those object that RegionQ will give False and True.Such as DiscretizeGraphics /@ {Graphics[Rectangle[]], Rectangle[]}... $\endgroup$ – yode Aug 23 '17 at 18:12
3
$\begingroup$

The typesetting system converts a Parallelogram object into a PolygonBox, so you could use:

toPolygon[p_Parallelogram] := Apply[
    Polygon,
    First @ Typeset`MakeBoxes[p, StandardForm, Graphics]
]

For your example:

toPolygon @ Parallelogram[{1, 2}, {{3, 4}, {6, 3}}]

Polygon[{{1, 2}, {4, 6}, {10, 9}, {7, 5}}]

| improve this answer | |
$\endgroup$
3
$\begingroup$

The 4th example in the Applications section of RegionEqual solves a similar problem (see here):

Find all ways to express the unit rectangle in terms of Parallelogram:

We can adapt the method used there to find all possible 4 vertex polygons:

reg = Parallelogram[{1, 2}, {{3, 4}, {6, 3}}];
target = Polygon[{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}];

cond = RegionEqual[reg, target];

target /. Solve[cond]
{Polygon[{{1, 2}, {4, 6}, {10, 9}, {7, 5}}], 
 Polygon[{{1, 2}, {7, 5}, {10, 9}, {4, 6}}], 
 Polygon[{{10, 9}, {4, 6}, {1, 2}, {7, 5}}], 
 Polygon[{{10, 9}, {7, 5}, {1, 2}, {4, 6}}], 
 Polygon[{{7, 5}, {1, 2}, {4, 6}, {10, 9}}], 
 Polygon[{{7, 5}, {10, 9}, {4, 6}, {1, 2}}], 
 Polygon[{{4, 6}, {1, 2}, {7, 5}, {10, 9}}], 
 Polygon[{{4, 6}, {10, 9}, {7, 5}, {1, 2}}]}
| improve this answer | |
$\endgroup$
2
$\begingroup$
prim = Parallelogram[{1, 2}, {{3, 4}, {6, 3}}];

MeshPrimitives[DiscretizeGraphics[prim], 2]

{Polygon[{{1., 2.}, {7., 5.}, {10., 9.}, {4., 6.}}]}

 % // Graphics

enter image description here

Also:

MeshPrimitives[BoundaryDiscretizeGraphics[prim], 2] (* or *)
BoundaryDiscretizeGraphics[prim]["BoundaryPolygons"]
| improve this answer | |
$\endgroup$
2
$\begingroup$

If you don't care duplicated end points:

Polygon @@ RegionBoundary[Parallelogram[{1, 2}, {{3, 4}, {6, 3}}]]

If you don't want duplicated end points:,

Polygon @@ 
 Drop[RegionBoundary[Parallelogram[{1, 2}, {{3, 4}, {6, 3}}]], 
  None, -1]
| improve this answer | |
$\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.