AnsweredAssumed Answered

Rotate, Scale Geometry Programmatically

Question asked by arnel.19880 on Oct 3, 2018
Latest reply on Oct 16, 2018 by arnel.19880

I need to implement a way to rotate/scale a polygon graphic on the MapView and SceneView. I couldn't fine a way using the API to apply these transformations to the geometries so I have tried different approaches, all of them involve modifying the vertices to calculate the position of each vertex after the transformation in order to obtain the new geometry.


My first implementation uses the WPF RotateTransform/ScaleTransform class to transform each individual point using a specific angle and the center of the polygon as the CenterX, CenterY of the transformations. The rotate method receives all the points in screen coordinates, so I have to convert the MapPoints using the LocationToScreen method and after getting the result I convert back to MapPoint using the ScreenToLocation(MapView) and ScreenToBaseSurface (SceneView).


On the second implementation I don't use the WPF Transform class, instead I use  trigonometry to get the position of each point after the rotation using the center of the polygon as anchor point.


Both approaches seems to rotate the polygon, however, it isn't working fine. The position of the polygon changes, the center should stay in the same place. The geometry gets deformed after a few rotations.

Any help will be highly appreciated.


Thanks in advance.