TransWikia.com

Get coordinates of Translated Polygon

Mathematica Asked on January 14, 2021

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?

One Answer

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}}

Correct answer by kglr on January 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP