Anyone here have some background in linear algebra?
I've got a problem I need to solve, and I need it in VB6, but I can't even find a clean solution in any language.
Let me see if I can outline the problem somewhat clearly. Okay, all of this will be in 3D space. In this space, we can define some origin. Typically, in my situation, this will be a point on the floor in the middle of some room. Next, we need to define X+, Y+, and Z+ in the room. Think of the X+ and Y+ as a piece of graph-paper lying on the floor with its origin on the room's origin. The Z+ is simply the third (UP) dimension.
Okay, with this information, we can define any other point in the room, even points that aren't on the floor. They'll just have a Z+ value other than zero. So, to represent any arbitrary point in the room, we might have the following UDT:
Code:
Public Type VectorType
' A 3D coordinate (point) somewhere in space with some pre-defined origin and axis basis.
' Typical units are mm.
xPos As Double ' Some X position in space relative to some origin.
yPos As Double ' Some Y position in space relative to some origin.
zPos As Double ' Some Z position in space relative to some origin.
End Type
Now, that room origin and axis system is often called an "ordered basis", or just a "basis".
I should briefly talk about something else too, the right-hand-rule. Basically, this states that, while you're looking down any axis at the origin, counter-clockwise rotations are positive, and clockwise rotations are negative. It's easy to visualize this as a piece of graph paper. You don't often think about it, but you're looking down the Z-axis when you're looking at graph paper. Rotations around this Z-axis around the origin are positive if they're counter-clockwise, rotating toward Y+ off of the X+ axis, which typically shoots off to the right. If we extrapolate this to 3-axes (3D), this is the right-hand-rule. Here's an image I once made trying to illustrate this:
Okay, forging on. Again, we've defined a "basis" (origin, X+ direction, Y+ direction, and Z+ direction) for our room. However, in truth, we can define any basis we like, so long as it's got an origin, an X+ direction, a Y+ direction, and a Z+ direction. Also, as another FYI, these three directions are required to be orthogonal.
Since we can actually define any basis we like, we have the following UDT:
Code:
Public Type BasisType
' To be correct, the line segments o-x, o-y, & o-z must be orthogonal.
' Right-hand-rule is assumed.
oVec As VectorType ' The origin of the basis, a vector.
xVec As VectorType ' X direction of basis, a vector, ideally one unit away from o.
yVec As VectorType ' Y direction of basis, a vector, ideally one unit away from o.
zVec As VectorType ' Z direction of basis, a vector, ideally one unit away from o.
End Type
The origin (oVec) will always be in reference to our room's basis. However, the other three vectors can be rotated such that they're not parallel to the room's axes (X+, Y+, Z+).
Ok, one last piece of groundwork. To rotate from one basis to another, we can have what we call Euler angles. Their UDT would look something like the following:
Code:
Public EulerAnglesType
' Preferrably, these will be in degrees (but VB6 prefers radians for trig functions).
xRot As Double
yRot As Double
zRot As Double
End Type
Ok, we can also talk about a translation (movement of the origin), but I'm mostly concerned about the rotation, so let's just forget changes in the origin of our two bases.
(Also, some might be having visions of quaternions and/or transformation matrices, but let's set those aside for now too.)
Ideally, what I'd like is code that solves for the Euler angles that would rotate one basis to another basis. In other words, given two bases (defined with the above BasisType UDT), how would I solve for the Euler angles (defined with the above, EulerAnglesType)?
I'll be quite interested in the replies.
Thanks,
Elroy
EDIT1: Ohhh, and the solution must follow the right-hand-rule.