WPF: Rotate 2D Vector
I want to rotate a given 2D (!) Vector, is there a built-in WPF function to do this? I am currently 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 it should also be possible by multiplying the given vector by the rotation matrix? Anyway, I don't understand, can someone please provide an example? Thanks!
a source to share
You should have a look at System.Windows.Media.Matrix.Rotate (...) . Using this method, you can create a rotation matrix that you can apply to your vector using the static Vector.Mulitply (...) method or the Matrix.Transform (...) method .
I still haven't used the Matrix class, but my first idea was to use something like this:
Matrix m = Matrix.Identity;
m.Rotate(90);
Vector v2 = m.Transform(v);
Note that the Matrix class uses 3x3 matrices, but this does not mean that it is intended for 3D. It's more intended for 2D (as you can read in the documentation). Additional parameters are used to combine a translation with another transformation in one transformation. See Homogeneous coordinates for details .
a source to share