2013-01-21 220 views
2

我需要旋转在WPF单个坐标 - C#。旋转3D坐标

x, y,z存储在GeometryModel3D[]点。

例如,坐标(x,y,z)在spefic-axis处旋转。

[UPDATE]使用旋转变换的四元数。问题是我没有得到新的矢量值,当我查看点云时,它似乎在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)); 

我仍然无法获得正确的价值转换。

我想对从kinect扫描的第二个点云应用旋转变换。由于第一次扫描数据不涉及旋转,捕获数据和用法的代码如下所示:

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++; 
    } 
} 
+0

的例子是由绕y轴旋转90度的一个点? – sinelaw

+0

是的,但我的代码显示似乎错了,因为我不知道如何设置的矩阵.. – akuhero

+0

[链接]的Matrix3D结构(http://msdn.microsoft.com/en-us/library/system.windows.media .media3d.matrix3d(v = vs.90).aspx) – akuhero

回答

2

创建任何类型的矩阵。例如一个rotation matrix,然后使用静态方法Vector.Multiply(...) 另请参阅this postMSDN general transformation概述。为的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); 
    
+0

对不起,我还是不明白如何使用旋转矩阵来实现旋转。希望你可以通过简单的代码:)。 – akuhero

+0

@akuhero,你看由马蒂亚斯给出的计算器链接?有一个简单的代码示例那边 – sinelaw

+0

@sinelaw,我没看,但如何应用到3D矢量? – akuhero