0

I need to define a 3D transformation and apply it to a point p ={1000, 0, 0}.

For example, say one needs to apply a Pi/2 rotation around the z axis. I defined the transformation using a MatrixTransform3D. From the code below:

EXPECTED OUTPUT: trPoint = {0, 1000, 0}

ACTUAL OUTPUT: trPoint = {0, -1000, 0}.

QUESTION: Perhaps the Transform3D.Transform method applies the inverse transform instead?

    private void testTransformationMat() {
        Point3D p = new Point3D(1000, 0, 0);

        double angle = System.Math.PI / 2;

        double cos = System.Math.Cos(angle);
        double sin = System.Math.Sin(angle);

        Matrix3D mat_z = new Matrix3D(cos, -sin, 0, 0,sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

        Transform3D tr = new MatrixTransform3D(mat_z);

        Point3D trPoint = tr.Transform(p);

        Debug.WriteLine(trPoint);

    }

EDIT: To get things straight, as far as I've always known, a homogeneous transformation is applied multiplying a 4x4 matrix with a 4x1 vector. For a +45deg rotation around the z axis, under right-hand convention, we obtain:

0.707 -0.707 0 0         1000        707
0.707 0.707 0 0     X    0       =   707
0 0 1 0                  0           0
0 0 0 1                  1           0

If we invert the matrix, the multiplication returns a negative y component which is not coherent with a +45deg rotation around Z.

0.707 0.707 0 0         1000        707
-0.707 0.707 0 0     X    0       =  -707
0 0 1 0                  0           0
0 0 0 1                  1           0
Nic
  • 1,262
  • 2
  • 22
  • 42
  • Matrix3D mat_z = new Matrix3D(cos, -sin, 0, 0,sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); -> change -sin to sin. I did not do the calculation but that sounds like the reason for an inverse on one of the axis. – Ahmad Dec 08 '15 at 16:30
  • Hi @Ahmad, thanks for the quick reply. mat_z is defined as a standard z-positive rotation ( https://en.wikipedia.org/wiki/Rotation_matrix ) . If I transpose the whole matrix it would work, but why should I define a transpose instead of the correct matrix? I am sure I'm missing something. – Nic Dec 08 '15 at 16:37
  • Have a look at http://www.idomaths.com/linear_transformation_3d.php , for positive z-axis ... the expected if I understand correctly is : Matrix3D mat_z = new Matrix3D(cos, sin, 0, 0,-sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); – Ahmad Dec 08 '15 at 16:54
  • This is getting so confusing. The website you mentioned reports all matrices which are transposed wrt the definition I've always known, see http://scipp.ucsc.edu/~haber/ph216/rotation_12.pdf for example. – Nic Dec 08 '15 at 17:15
  • I wanted to mark my answer as deleted so that you can have better chances of getting this question answer .. but that does not seem to be possible ... – Ahmad Dec 09 '15 at 16:29
  • @Ahmad no worries, and thanks for helping out! It seems that Point3D is defined row-wise, therefore the rotation matrix needs to be transposed. I am still wondering what exactly the Transform3d.Transform() method does in terms of matrices. – Nic Dec 09 '15 at 16:37
  • Yeah i have seen the answer on the question you linked, it is not clear for documentation on msdn though as far as i could tell ... good luck Nic. – Ahmad Dec 09 '15 at 16:40

1 Answers1

0

From 3-D Transformations Overview

Note:Windows Presentation Foundation (WPF) 3-D is a right-handed system, which means that a positive angle value for a rotation results in a counter-clockwise rotation about the axis.

Ahmad
  • 1,462
  • 15
  • 23
  • Hi @Ahmad, please check the edit to my question. If I multiply the matrix you suggested Matrix3D mat_z = new Matrix3D(cos, sin, 0, 0,-sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); the result is not coherent. My best guess is that the transform() method does not apply a 4x4 times 4x1 product. I am still lost though – Nic Dec 09 '15 at 14:30
  • I have also added a similar question specifically for Matrix3D http://stackoverflow.com/questions/34181667/matrix3d-for-a-positive-rotation-around-z-in-wpf – Nic Dec 09 '15 at 14:47