public static class GeometryExtension { public static Polyline Rotate(this Polyline polyline, double rotation, MapPoint fixPoint) { var transform = new CompositeTransform {Rotation = rotation, CenterX = fixPoint.X, CenterY = fixPoint.Y}; var output = new Polyline(); foreach(var path in polyline.Paths) { var pc = new ESRI.ArcGIS.Client.Geometry.PointCollection(); foreach (var mapPoint in path) pc.Add(mapPoint.Transform(transform)); output.Paths.Add(pc); } return output; } private static MapPoint Transform(this MapPoint mapPoint, Transform transform) { var point = transform.Transform(new System.Windows.Point(mapPoint.X, mapPoint.Y)); return new MapPoint(point.X, point.Y); } }
To avoid too much formula, you can also use a CompositeTransform:
Then you can rotate a polyline by code like : var result = myPolyline.Rotate(angle, fixPoint);
Thanks Barry, thanks Dominique
I could rotate the polyline using the raw math algo i got from u, barry. Dominique snippet is quite neat so i will replace it. Problem continues thou. The polyline being rotated follows a certain buffer. So consider it like the pivot point for the rotation is the a point buffered at a radius exactly equal to the the length of the polyline. The funny part is that as it rotates, the tip of the polyline touches the buffer graphics at some points and falls inside the buffer at some points. I realized the buffered graphics is not a perfect circle.
Any idea? The last resort would be to have sort of a spegetti implementation having geometry service and finding the coordinate the elongated polyline touches the buffer graphics, take the new XY, redraw the polyline with the pivot point (x0, y0) to the new point (x1, y1).
Thanks Folks.