Reputation: 1310
Let P be a Point3D such that P = {1,0,0} . I need to define a rotation around the Z axis of +45deg and apply it to P. Under a right-hand convention, the transformation M is defined:
M =
0.707 -0.707 0 0
0.707 0.707 0 0
0 0 1 0
0 0 0 1
Mathematically:
M x P =
0.707 -0.707 0 0 1 0.707
0.707 0.707 0 0 X 0 = 0.707
0 0 1 0 0 0
0 0 0 1 1 1
here is my C# code:
private void testMatrix3D() {
double angle_rad = Math.PI/4;
double cos = Math.Cos(angle_rad);
double sin = Math.Sin(angle_rad);
Matrix3D mat = new Matrix3D(cos, -sin, 0, 0, sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
Point3D p = new Point3D(1, 0, 0);
Point3D transformedP = mat.Transform(p);
Debug.WriteLine("p = " + p);
Debug.WriteLine("mat = " + mat);
Debug.WriteLine("transformedP = " + transformedP);
}
Unfortunately, the result is transformedP = {0.707, -0.707, 0} and NOT transformedP= {0.707, 0.707, 0}
What am I doing wrong?
Upvotes: 0
Views: 622
Reputation: 11196
Since WPF stores vectors in matrices row-wise you need to exchange those:
Matrix3D mat = new Matrix3D(cos, sin, 0, 0, -sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
Upvotes: 1