获取旋转后的坐标 [英] Get coordinates after rotation

查看:120
本文介绍了获取旋转后的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个矩形和2椭圆上矩形的左和右边缘的用户控件。
我在后,找出用户控件的坐标intrested一个平移和旋转的RenderTransform已发生。

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.

编辑:
搜索互联网一段时间后我能在这里找到答案,我的问题的 http://forums.silverlight.net/forums/p/136759/305241.aspx 所以我想我会发布的链接有这个问题,其他的人。

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.

我标志着托马斯Petricek的职位作为一个答案,因为它是最接近的一个解决方案。

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

在一般情况下,可以表示为转换矩阵。要编写转换,你只是乘以矩阵,所以这是一个很组合的解决方案。代表旋转矩阵包含的的和的 COS 的从上面的方法值。请参见旋转矩阵(和的变换矩阵在维基百科上)。

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.

这篇关于获取旋转后的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆