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