1
$\begingroup$

I have many polygons of the following form that I wish to do more complicated processing and analysis based on it's updated location (such as relationships between geometries).

Translate[Polygon[{{0, 0}, {0, 50}, {100, 50}, {100, 0}}], {954, 840}]

I thought I had found my solution of how to recover the coordinates of a translated Polygon from an earlier thread about Points. However, when I tried to applied Normal M12.1 just returns the expression again.

Normal[Translate[Polygon[{{0, 0}, {0, 50}, {100, 50}, {100, 0}}], {954, 840}]]

I've tried some more complicated ways to extract the coordinates from a Graphics object to no avail. Does anyone have any suggestions about how they would recover the Polygons updated extents?

$\endgroup$
1
$\begingroup$
translateToNormal[t_Translate] := TranslationTransform[#2] /@ # & @@ t

tp = Translate[Polygon[{{0, 0}, {0, 50}, {100, 50}, {100, 0}}], {954, 840}]

translateToNormal[tp]
 Polygon[{{954, 840}, {954, 890}, {1054, 890}, {1054, 840}}]

Alternatively,

translateToNormal2 = # /. Translate -> (TranslationTransform[#2] /@ # &) &;

translateToNormal2 @ tp
 Polygon[{{954, 840}, {954, 890}, {1054, 890}, {1054, 840}}]
Graphics[{FaceForm[], EdgeForm[{AbsoluteThickness[10], Red}], translateToNormal[tp],
  EdgeForm[{Thin, Black}], tp}]

enter image description here

To get the coordinates:

normalCoords[t_Translate] := TranslationTransform[#2] @ #[[1]] & @@ t
normalCoords[tp]
{{954, 840}, {954, 890}, {1054, 890}, {1054, 840}}
$\endgroup$
1
  • $\begingroup$ It works thanks. I wasn't able to reverse what #2 and # are actioning upon? $\endgroup$ – BBirdsell Dec 10 '20 at 6:03

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.