This method will rotate a list of 3D coordinate points a variable amount of degrees around the X, Y, and Z axis in a standard coordinate plane. Any amount of points can be given and any angle of rotation can be given for each individual X, Y, and Z axis as long as the points all share the same coordinate system.
The math for this is based off of these website links for a general 3D cartesian coordinate rotation.
Each X, Y, and Z component of a point are affected by the new rotation around the X, Y, and Z axis in that order. (Note that any other order of rotations can result in different resultant point locations, so keep that in mind when setting parameters.) Because each cartesian component is affected by each axis' rotation, we can represent the rotation of the point in terms of the following three matrices:
[1 0 0 ]
Rx(theta) = [0 cos(theta) -sin(theta)]
[0 sin(theta) cos(theta)]
[cos(theta) 0 sin(theta)]
Ry(theta) = [0 1 0 ]
[-sin(theta) 0 cos(theta)]
[cos(theta) -sin(theta) 0]
Rz(theta) = [sin(theta) cos(theta) 0]
[0 0 1]
Finally multiply each point by the determinate of each of these matrices multiplied together to get the new point after being rotated around each axis.
[X] [X] [Y
] = A * [Y] [Z`] [Z]
(Where A is Rz(theta) * Ry(theta) * Rx(theta); X, Y, Z are the original points; X, Y
, Z` are the new points.)
So for example, rotating point [1, 0, 0] 90 degrees around the Z-axis would result in this point:
| 0 -1 0 | |1| |0| | 1 0 0 | * |0| = |1| | 0 0 1 | |0| |0|
- Template Parameters
-
- Parameters
-
vPointCloud | - A reference to a vector of CoordinatePoint<T> structs used to store the X, Y, and Z values of each point. This will contain the rotated modified points after this function completes. |
dXRotationDegrees | - The degree amount to rotate the points around the x-axis. |
dYRotationDegrees | - The degree amount to rotate the points around the y-axis. |
dZRotationDegrees | - The degree amount to rotate the points around the z-axis. |
- Note
- Rotation will happen the the order of X-axis, Y-axis, Z-axis with the positive angle direction being clockwise when looking from the origin and looking down the vector arrow.
- Author
- clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
- Date
- 2024-04-21
291 {
292
293 double dXRotationRadians = (dXRotationDegrees * M_PI) / 180.0;
294 double dYRotationRadians = (dYRotationDegrees * M_PI) / 180.0;
295 double dZRotationRadians = (dZRotationDegrees * M_PI) / 180.0;
296
297
298 double dCosA =
cos(dXRotationRadians);
299 double dSinA =
sin(dXRotationRadians);
300
301 double dCosB =
cos(dYRotationRadians);
302 double dSinB =
sin(dYRotationRadians);
303
304 double dCosC =
cos(dZRotationRadians);
305 double dSinC =
sin(dZRotationRadians);
306
307
308
309 double dAXX = dCosC * dCosB;
310 double dAXY = dCosC * dSinB * dSinA - dSinC * dCosA;
311 double dAXZ = dCosC * dSinB * dCosA + dSinC * dSinA;
312
313 double dAYX = dSinC * dCosB;
314 double dAYY = dSinC * dSinB * dSinA + dCosC * dCosA;
315 double dAYZ = dSinC * dSinB * dCosA - dCosC * dSinA;
316
317 double dAZX = -dSinB;
318 double dAZY = dCosB * dSinA;
319 double dAZZ = dCosB * dCosA;
320
321
323 {
324
325 T tX = static_cast<T>((dAXX * stPoint.tX) + (dAXY * stPoint.tY) + (dAXZ * stPoint.tZ));
326 T tY = static_cast<T>((dAYX * stPoint.tX) + (dAYY * stPoint.tY) + (dAYZ * stPoint.tZ));
327 T tZ = static_cast<T>((dAZX * stPoint.tX) + (dAZY * stPoint.tY) + (dAZZ * stPoint.tZ));
328
329 stPoint.tX = tX;
330 stPoint.tY = tY;
331 stPoint.tZ = tZ;
332 }
333 }
__device__ __forceinline__ float1 cos(const uchar1 &a)
__device__ __forceinline__ float4 sin(const uchar4 &a)
This struct represents a point in a 3D coordinate system.
Definition NumberOperations.hpp:42