WPF:旋转 2D 矢量
我想旋转给定的 2D (!) 矢量,是否有 WPF 内置函数可以实现此目的? 目前我正在手动执行此操作:
Vector v = new Vector();
v.X = 10; v.Y = 10;
Vector v2 = new Vector();
v2.X = v.X * Math.Cos(-90 * 180 / Math.PI) - v.Y * Math.Sin(-90 * 180 / Math.PI);
v2.Y = v.Y * Math.Cos(-90 * 180 / Math.PI) + v.X * Math.Sin(-90 * 180 / Math.PI);
我认为通过将给定向量与旋转矩阵相乘也应该可以实现?无论如何,我不明白,有人可以给我一个例子吗?谢谢!
I want to rotate a given 2D (!) Vector, is there a WPF built-in function for this?
Currently I'm doing it manually:
Vector v = new Vector();
v.X = 10; v.Y = 10;
Vector v2 = new Vector();
v2.X = v.X * Math.Cos(-90 * 180 / Math.PI) - v.Y * Math.Sin(-90 * 180 / Math.PI);
v2.Y = v.Y * Math.Cos(-90 * 180 / Math.PI) + v.X * Math.Sin(-90 * 180 / Math.PI);
I think this should be also possible by multiplying the given vector with a rotation matrix? Anyways, I don't get it, can someone please give me an example? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该查看 System.Windows.Media .Matrix.Rotate(...)。使用此方法,您可以创建一个旋转矩阵,然后使用静态 Vector.Mulitply(...) 方法或矩阵。 Transform(...) 方法。
到目前为止,我从未使用过 Matrix 类,但我的第一个想法是使用这样的东西:
请注意,Matrix 类使用 3x3 矩阵,但这并不意味着它适用于 3D。它更适合 2D(正如您可以在文档中阅读的那样)。附加参数用于将翻译与另一个转换组合在一个转换中。有关详细信息,请参阅齐次坐标。
You should have a look at System.Windows.Media.Matrix.Rotate(...). Using this method, you can create a rotation matrix which you can then apply to your vector using the static Vector.Mulitply(...) method or the Matrix.Transform(...) method.
I have never used the Matrix class so far, but my first idea was to use something like this:
Note that the Matrix class uses 3x3 matrices, but that does not mean it is intended for 3D. It is rather intended for 2D (as you can read in the documentation). The additional parameters are used for combining a translation with another transformation in one transformation. See Homogenous coordinates for details.