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
273 {
274
275 double dXRotationRadians = (dXRotationDegrees * M_PI) / 180.0;
276 double dYRotationRadians = (dYRotationDegrees * M_PI) / 180.0;
277 double dZRotationRadians = (dZRotationDegrees * M_PI) / 180.0;
278
279
280 double dCosA =
cos(dXRotationRadians);
281 double dSinA =
sin(dXRotationRadians);
282
283 double dCosB =
cos(dYRotationRadians);
284 double dSinB =
sin(dYRotationRadians);
285
286 double dCosC =
cos(dZRotationRadians);
287 double dSinC =
sin(dZRotationRadians);
288
289
290
291 double dAXX = dCosC * dCosB;
292 double dAXY = dCosC * dSinB * dSinA - dSinC * dCosA;
293 double dAXZ = dCosC * dSinB * dCosA + dSinC * dSinA;
294
295 double dAYX = dSinC * dCosB;
296 double dAYY = dSinC * dSinB * dSinA + dCosC * dCosA;
297 double dAYZ = dSinC * dSinB * dCosA - dCosC * dSinA;
298
299 double dAZX = -dSinB;
300 double dAZY = dCosB * dSinA;
301 double dAZZ = dCosB * dCosA;
302
303
305 {
306
307 T tX = static_cast<T>((dAXX * stPoint.tX) + (dAXY * stPoint.tY) + (dAXZ * stPoint.tZ));
308 T tY = static_cast<T>((dAYX * stPoint.tX) + (dAYY * stPoint.tY) + (dAYZ * stPoint.tZ));
309 T tZ = static_cast<T>((dAZX * stPoint.tX) + (dAZY * stPoint.tY) + (dAZZ * stPoint.tZ));
310
311 stPoint.tX = tX;
312 stPoint.tY = tY;
313 stPoint.tZ = tZ;
314 }
315 }
__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