Rotating a 3D coordinate

akuhero picture akuhero · Jan 21, 2013 · Viewed 10.1k times · Source

I need to rotate a single coordinate in WPF - C#.

The values x, y,z stored in GeometryModel3D[] points.

For example, coordinate(x, y, z) rotate at speficic-axis.

[UPDATE] Rotation transformation using quaternion. The problem are I don't get the new vector value and when I view the pointcloud, It seem drag away in Meshlab.

Matrix3D m = Matrix3D.Identity;
Quaternion q = new Quaternion(new Vector3D(320 / 2, y, maxDepth - minDepth), 90);
m.Rotate(q);
Vector3D myVectorToRotate = new Vector3D(((TranslateTransform3D)points[i].Transform).OffsetX,                        ((TranslateTransform3D)points[i].Transform).OffsetY,     ((TranslateTransform3D)points[i].Transform).OffsetZ);

m.Transform(myVectorToRotate);
pointcloud.Add(new Point3D(myVectorToRotate.X,myVectorToRotate.Y,myVectorToRotate.Z));

I'm still can't get the correct value transformation.

I want to apply rotation transformation for 2nd point cloud scanned from kinect. Since the 1st scan data don't involved rotation, the code for capture data and usage is like below:

for (int y = 0; y < 240; y += resolution)
{
    for (int x = 0; x < 320; x += resolution)
    {
        if (((TranslateTransform3D)points[i].Transform).OffsetZ >= minDepth
              && ((TranslateTransform3D)points[i].Transform).OffsetZ <= maxDepth)
        {
            pointcloud.Add(new Point3D(((TranslateTransform3D)points[i].Transform).OffsetX,                                                        ((TranslateTransform3D)points[i].Transform).OffsetY,                                              ((TranslateTransform3D)points[i].Transform).OffsetZ));
        }
        i++;
    }
}

Answer

Matthias picture Matthias · Jan 21, 2013

Create any kind of matrix. For example a rotation matrix and then use the static method Vector.Multiply(...) See also this post and the MSDN general transformation overview.

Examples for Vector3D:

  1. 3D transformation WPF
  2. Rotate a vector by quaternion

    Vector3D v = new Vector3D(1.0, -1.0, 2.0);
    ...
    AxisAngleRotation3D axisAngle = new AxisAngleRotation3D(axis, angle);
    RotateTransform3D myRotateTransform = new RotateTransform3D(axisAngle, centerVector);
    v.Multiply(myRotateTransform);