I rotate a vector using the following code:

   var newVectorX = Math.Cos(step) * normalizedVector.X 
                                 - Math.Sin(step) * normalizedVector.Y;

                var newVectorY = - Math.Sin(step) * (normalizedVector.X )
                                 + Math.Cos(step) * normalizedVector.Y;

I tried to create a 2x2 matrix so I just can multiply my normalized vector with the matrix. The result would be the new rotated vector instead the coordinates.

rotation matrix

Unfortunately System.Windows.Media.Matrix doesn't support 2x2 matrices. I couldn't find any implementation of this rotation matrix so far. How would you implement this?

有帮助吗?

解决方案

Actually, System.Windows.Media.Matrix is exactly what you need. While it may seem that you want a 2x2 matrix, using a 3x3 matrix allows for translations too. Just use a System.Windows.Media.Matrix and ignore the part you don't need.

Matrix rotate = Matrix.Identity;
rotate.Rotate(step * 180 / Math.PI);    // Rotate() takes degrees
Vector newVector = rotate.Transform(normalizedVector);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top