문제

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