I'm not sure who will actually benefit from these procedures, but I suspect a few people will occasionally find them through Google. I've just got quite a bit of work into them, and wanted to share.
Also, for those versed in linear algebra, let me provide a few definitions and some context.
1) Everything follows the right-hand-rule.
2) In the attached module, the concept of a "Segment" is actually just an ordered basis. It's basically four 3D vectors. One defines the origin, one defines the X (forward, East) axis, one defines the Y (left, North) axis, and one defines the Z (up) axis. These three axes are orthonormal (i.e., orthogonal with one unit length). The origin is not built into the three orthonormal axes. In other words, these three axes are setup as if the origin is always <0,0,0>. This makes rotations of these Segments much easier.
3) When using quaternions, they always follow the JPL convention and are unit quaternions (i.e., no built-in scaling).
4) There are some functions that are specific to emulating functions found in the BodyBuilder language by Vicon. These may be a bit unusual for a "pure" mathematician, but they serve my purposes.
5) When converting from Euler angles to quaternions (and vice-versa), many procedures found on the web will only do it in one angle order (typically ZYX). However, the attached procedures will do it in any order of your choosing. The only online reference for this that I could find was an old scanned 1977 NASA document, specifically Appendix A.
6) If you actually start studying this code, note that all the rotations are actually performed using quaternions. In other words, Euler angles aren't used directly for anything other than reporting results.
7) I'm also wondering if there's possibly some graphical API interface that I could be using to do some of this faster. Any ideas on that front are more than welcome. Don't forget though that I'll always need to specify the angle order when moving between Euler angles and quaternions, and not have it pre-defined.
The BAS module was too large to put into a CODE block, so it's attached. However, here's a list of functions.
Enjoy,
Elroy
EDIT1: Just to mention it, when doing Euler2Quat (or Quat2Euler), there are actually twelve possible orders, and I've only covered six of them. The six I've covered are: xyz, xzy, yzx, yxz, zxy, & zyx. There's also a way to get from Euler angles to a quaternion whereby you do the rotation on the first axis, then the second, and then finish up by returning to the first axis. In other words, these rotation orders would be denoted as: xyx, xzx, yxy, yzy, zxz, & zyz. At present, I've got no need for this approach, and they're not currently covered in the attached code.
Also, for those versed in linear algebra, let me provide a few definitions and some context.
1) Everything follows the right-hand-rule.
2) In the attached module, the concept of a "Segment" is actually just an ordered basis. It's basically four 3D vectors. One defines the origin, one defines the X (forward, East) axis, one defines the Y (left, North) axis, and one defines the Z (up) axis. These three axes are orthonormal (i.e., orthogonal with one unit length). The origin is not built into the three orthonormal axes. In other words, these three axes are setup as if the origin is always <0,0,0>. This makes rotations of these Segments much easier.
3) When using quaternions, they always follow the JPL convention and are unit quaternions (i.e., no built-in scaling).
4) There are some functions that are specific to emulating functions found in the BodyBuilder language by Vicon. These may be a bit unusual for a "pure" mathematician, but they serve my purposes.
5) When converting from Euler angles to quaternions (and vice-versa), many procedures found on the web will only do it in one angle order (typically ZYX). However, the attached procedures will do it in any order of your choosing. The only online reference for this that I could find was an old scanned 1977 NASA document, specifically Appendix A.
6) If you actually start studying this code, note that all the rotations are actually performed using quaternions. In other words, Euler angles aren't used directly for anything other than reporting results.
7) I'm also wondering if there's possibly some graphical API interface that I could be using to do some of this faster. Any ideas on that front are more than welcome. Don't forget though that I'll always need to specify the angle order when moving between Euler angles and quaternions, and not have it pre-defined.
The BAS module was too large to put into a CODE block, so it's attached. However, here's a list of functions.
Code:
'
' List of functions herein:
'
' Make Segment (ordered basis) Functions:
'
' SegFrom5Pts
' SegFrom3Pts
' SegFromLines
'
' Conversion Functions:
'
' Euler2Quat
' Quat2Euler
' Seg2Quat ' Abandons origin.
' Quat2Seg ' Leaves origin as <0,0,0>.
' Seg2Euler ' Abandons origin.
' Euler2Seg ' Leaves origin as <0,0,0>
'
' Rad2Deg
' Deg2Rad
' VecRad2Deg
' VecDeg2Rad
'
' Axes2Quat ' Similar to Seg2Quat.
' Quat2Fwd ' Forward (x) axis of quat. Same as X axis of segment.
' Quat2Left ' Left (y) axis of quat. Same as Y axis of segment.
' Quat2Up ' Up (z) axis of quat. Same as Z axis of segment.
' AxisAngle2Quat ' This is the rotation axis, not any segment axis.
' QuatAxis ' This returns the rotation axis.
' QuatAngle ' This returns the rotation angle.
'
' Rotation Functions:
'
' RotSeg (with axis & angle)
' RotSegByQuat
' RotVec (with axis & angle)
' RotVecByQuat
' RotQuat (by quat)
' UnRotQuat (by quat) ' Same as a QuatBetween function: UnRotQuat(q2, q1).
'
' Angles Between Functions:
'
' EulerBetweenSegs = -<seg1, seg2, order> (BodyBuilder)
' FixedBetweenSegs = <seg1, seg2, order> (BodyBuilder)
' EulerBetweenQuats
' (QuatBetweenQuats) ' Do UnRotQuat(q2, q1).
'
' Quick Functions:
'
' XProd
' DotProd
'
' VecAvg
' VecSum
' VecDif
' VecAddNum
' VecDivNum
' VecMultNum
' VecMag
' NegVec
' UnitVec
'
' NegQuat
'
' MakeLine
' MakeVec
' MakeQuat
'
' Trigonometry Functions:
'
' ACos
' ASin
' ATan2
'
' Debugging Functions:
'
' AngString
' PntString
'
' VecString
' QuatString
' SegString
'
Enjoy,
Elroy
EDIT1: Just to mention it, when doing Euler2Quat (or Quat2Euler), there are actually twelve possible orders, and I've only covered six of them. The six I've covered are: xyz, xzy, yzx, yxz, zxy, & zyx. There's also a way to get from Euler angles to a quaternion whereby you do the rotation on the first axis, then the second, and then finish up by returning to the first axis. In other words, these rotation orders would be denoted as: xyx, xzx, yxy, yzy, zxz, & zyz. At present, I've got no need for this approach, and they're not currently covered in the attached code.