How to rotate a polyline on a given xy pivot point

3718
5
05-23-2011 04:47 PM
by Anonymous User
Not applicable
Original User: jbarry

Found this question on the EDN facebook page:
Michael Melaku
Seriously???  Aiight, i'm hanging on a problem. In a Silverlight Application on  ArcGIS Server 10, I'm trying to rotate a polyline with a certain defined  angle over a defined vertex, xy. Anyone with a clue? Thanks a zillion.


Maybe someone has some advice for Michael.

(Second, I'm not really into Silverlight yet, so I don't know if they've got some nifty coarse-grained geometry stuff one function call away, but if what you needed was some brute-force trig-based formula that I'm sure could be done client-side, see the attached text file.)


[ATTACH=CONFIG]6777[/ATTACH]
0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: MichaelMelaku

Thanks Jerry. I'll have to try out ur suggested approach. Well, i tried to implement the ITransform2D interface which as per the documentation applies for ArcGIS Server. It is to transform features including rotate, scale and move and all. I couldn't find a neat example so far.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
To avoid too much formula, you can also use a CompositeTransform:

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


Then you can rotate a polyline by code like : var result = myPolyline.Rotate(angle, fixPoint);
0 Kudos
by Anonymous User
Not applicable
Original User: jbarry

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 Dominique!! 

Yeah, I figured there was probably an easier way than the raw math approach.   Ok, I'm stepping out of the way now.  😉

Michael:

Glad to see you joined the forums here.  I hope you find them useful.  There are thousands of folks here from around the world who can help and thousands of posts here already you can search on.
0 Kudos
MichaelMelaku
New Contributor
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.
0 Kudos
by Anonymous User
Not applicable
Original User: jbarry

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.


Thanks Michael.   Hopefully it's just me, but I read your reply a few times and I'm struggling to visualize what you've described.  Once I think I'm getting it, the next sentence derails me.    Is this something you can draw as a mockup and include here?
0 Kudos