Rotating a 3D coordinate
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:
- 3D transformation WPF
-
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);
akuhero
Updated on June 04, 2022Comments
-
akuhero almost 2 years
I need to rotate a single coordinate in WPF - C#.
The values
x, y,z
stored inGeometryModel3D[]
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++; } }
-
akuhero over 11 yearssorry, i still don't understand how to achieve the rotation using rotation matrix. Hope you can help by simple code :).
-
sinelaw over 11 years@akuhero, did you look at the stackoverflow link given by Matthias? There is a simple code sample over there
-
akuhero over 11 years@sinelaw, I did look but how to apply to a 3D vector?
-
akuhero over 11 yearsthat why I can't solve it. I don't know how to form Matrix3D structure
-
Matthias over 11 yearsThe links above are a good starting point. But I will edit and add some more links to Vector3D examples. But cool, that you are giving a down-vote instead of providing an answer.
-
akuhero over 11 yearsit's a good start (can not be denied). Tq for your feeds. Hope hear something from you soon.
-
sinelaw over 11 years@Matthias actually I didn't downvote - in fact I upvoted (PS deleted my previous comment since I see you've added 3D-related stuff)
-
akuhero over 11 yearstq for update. When using quaternion, I don't know how to get the new point. [updated in question]
-
akuhero over 11 yearsBased on your example, I got an error at
Multiply
function.