I have a usercontrol which contains a rectangle and 2 ellipses on the left and right edge of the rectangle. I am intrested in finding out the coordinates of the user control after a translate and rotation rendertransform has occured.
The user control is contained in a canvas.
EDIT: After searching the internet for a while i was able to find the answer to my question here http://forums.silverlight.net/forums/p/136759/305241.aspx so I thought i'd post the link for other people having this issue.
I've marked Tomas Petricek's post as an answer because it was the closest one to the solution.
If you want to implement the calculation yourself, then you can use the following method to calculate a location of a point after rotation (by a specified number of degrees):
public Point RotatePoint(float angle, Point pt) {
var a = angle * System.Math.PI / 180.0;
float cosa = Math.Cos(a), sina = Math.Sin(a);
return new Point(pt.X * cosa - pt.Y * sina, pt.X * sina + pt.Y * cosa);
}
In general, you can represent transformations as matrices. To compose transformations, you'd just multiply the matrices, so this is a very composable solution. The matrix to represent rotation contains the sin and cos values from the method above. See Rotation matrix (and Transformation matrix) on Wikipedia.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With