#include <archon/math/rotation.H>
Collaboration diagram for Archon::Math::Rotation3:
Public Member Functions | |
Rotation3 () | |
Rotation3 (const Vector3 &axis, double angle) | |
Rotation3 | operator- () const |
bool | operator== (const Rotation3 &r) const |
bool | operator!= (const Rotation3 &r) const |
void | combineWith (const Rotation3 &) |
Produce the combined rotation corresponding to a sequence of two rotation, the first one described by this object, and the second one passed as argument to this function. | |
Static Public Member Functions | |
static const Rotation3 & | zero () |
Public Attributes | |
Vector3 | axis |
double | angle |
The angle must be given in radians.
The axis must be a unit vector.
And think about this: In 2-D you can rotate about a point (0-D). In 3-D you can rotate about a line or an axis (1-D) and in 4-D you can rotate about a plane (2-D).
In fact we could also have defined the axis of rotation as a 3 x 1 matrix defining the 1-D sub space around which we are rotating. In 4-D this would become a 4 x 2 matrix, and in 2-D it would degenerate to a 2 x 0 matrix.
Maybe this representation could be used as a way of generalizing the rotation to a template describing rotations in any dimention where it makes sence.
In several contexts it would be beneficial to be able to produce a single axial rotation that when applied to the basis vectors of a coordinate system will orient it such that its negative z-axis is directed towards p and its x-axis is parallel with the x-z-place of the reference coordinate system.
A sollution always exists but is never unique. As is always the case for angles we have an inifinite set of sollutions in that v is as good as 2pi-v and as good as 2pi+v. This is not a problem, we just choose the smalles one in an absolute sence. if the angle is pi exactly there is no unique smallest angle. In this case we choose the positive alternative.
Another case that generates even more results is when the resulting direction of the local z-axis becomes parallel to the reference y-axis. In this case the local x-axis will always be parallel to the x-z-place of the reference system and we need another way to constraint the result. A sensible choice in this case would be the rotation leading to the shortest angle.
Again there is a special case where there is no unique rotation with a shortest angle - if you are looking staight down and you are asked to look straight up. In this case we should choose one of the two rotations that avoid yaw.
Please note that in cases such as when pi and -pi both are sollutions it could make a big difference which one is chosen if the result is used in animation.
So, how can it be computed:
Let:
O be the local origin.
a be the original direction of the local negative z-axis.
b be the direction from O to p.
P be a plane spanned by a and b and coincident with the local origin.
Q be a plane that is perpendicular to P, coincident with O and dividing the angle between a and b in half.
The primary constraint was to align a with b. Now, this can be achieved with any rotation-axis lying in Q.
For any such axis the proper rotation angle is determined as the smallest angle between the projections of a and b onto a plane perpendicular to the chosen rotation axis.
But, how do we choose among the rotation axes in Q?
Let:
c be the original direction of the local x-axis.
d be the new direction of the local x-axis after rotation.
A be the chosen rotation axis in Q coincident with O.
R be a plane perpendicular to A.
r be the direction of A, |r| = 1.
We must choose an axis in Q that at the same time it takes a to b, it takes c to d.
Let:
M(r, v) be the rotation matrix corresponing with the sought axial rotation.
y be the direction of the reference y axis.
Then:
b = M(r, v) a
d = M(r, v) c
d·y = 0
(M(r, v) c)·u = 0
(UNFINISHED!!!)
Please note, it would also be possible to determine a sequence of simpler rotations and then combine them through quaternion math, but I belive this would be bad for efficiency.
Definition at line 147 of file rotation.H.