Calculating Yaw and Roll in a arbitrary frame

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I'm trying to write an MFD that will mimic the functionality of the default HUDs and I need some help with the math.

I have a matrix made up of a x, a y, and a z reference vector. (Yes they are perpendicular to each-other). For eas of reference I am referint to these vectors as "vertical" "horizon" and "north" where horizon and north form a plane and vertical is that plane's "normal".

At the moment I know I can get pitch from the following...

x = dot product of vertical and vessel's z axis
Pitch angle = PI/2(radians) - acos (x)

Ideally Yaw would show 0 when the vessel's z axis is aligned with north and roll would be the angle of the vessel's x axis relative to the horizon/north plane.

Unfortunately I am having difficult visualizing how to get there. Any help would be greatly appreciated.:tiphat:

ETA:
It seems I asked almost this same question 2 years ago but never got an answer.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Make a projection matrix from one coordinate system to the other and then solve for the RPY or PYR angles?
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
projection matrix?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
projection matrix?

Also known as "Transformation matrix". Especially the affine transformation is pretty useful to know in Orbiter, a 4 x 4 matrix, with the top left 3x3 block being a classic rotation matrix and the forth column being a translation vector.

[ame="http://en.wikipedia.org/wiki/Transformation_matrix"]Transformation matrix - Wikipedia, the free encyclopedia[/ame]
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Ahh, I am familiar with transformation matrices, but wouldn't the 4th column and row be redundant seeing as the origin will always be the vessel's CoG?

Likewise how do I translate the matrices once I have them into pitch yaw and roll?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Ahh, I am familiar with transformation matrices, but wouldn't the 4th column and row be redundant seeing as the origin will always be the vessel's CoG?

Likewise how do I translate the matrices once I have them into pitch yaw and roll?

First you have to declare which coordinate system you want to use (remember: Orbiter is left-handed, while most others are right-handed)

When you can convert from one coordinate system to the other, you can then declare which convention you use for the angles. PYR for example. With that you can then solve the matrix to the angles. And with that solution, you can implement the resulting equation system in your MFD and solve for the respective angles.

The easiest solution would be inverting Orbiters transformation matrix and just plugging it directly into a PYR or RPY convention - if you need extra rotations there it you need to multiply the inverted matrix by this transformation first and then solve.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I'm sorry but I'm not quite following.

What do you mean when you say "solve the matrix to the angles", isn't that what I'm asking for assistance with?

What I have is a set of 3 vectors comprising the 3 rows of a 3x3 matrix. I have another set of vectors representing the vessel's x, y, and z axises also comprising the 3 rows of a 3x3 matrix.

The vectors for both matrices are defined in the ecliptic coordinate system. (I.E my vessel's "forward vector" is the direction of the vessel's Z axis in the ecliptic frame)

I can find pitch using the angle between my vessel's forward vector and my vertical reference axis. Is it possible to find yaw and roll in a similar manner? if so how do i do it?
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I can find pitch using the angle between my vessel's forward vector and my vertical reference axis. Is it possible to find yaw and roll in a similar manner? if so how do i do it?

Go the other way first: You have RPY and want to define the matrix by these angles. The resulting matrix with the triangular functions results in something like:

x1 = sin(pitch)*cos(yaw) - cos(pitch)*cos(roll)

Now, you look for good equations to combine, so that you get a chance to deploy the atan2() function, like: tan(yaw) = x1/z3 --> yaw = atan2(z3, x1)
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I am very confused.

What is RPY in this case if not Roll Pitch and Yaw? and how can I define the matrix by these angles if I don't have them in the first place? They are what I am trying to find.
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
What is RPY in this case and what do you mean "define the matrix by these angles"

I don't have the angles they are what I am trying to find.

OK... from Adam and Eve then. :lol:

RPY means Roll-Pitch-Yaw and PYR means Pitch-Yaw-Roll. These are two ways of how to order the three rotations (out of many other conventions).

Pitch-Yaw-Roll is what you know from aircraft: First you apply pitch around the X axis, then you rotate by yaw around the resulting Y axis (rotated with the pitch rotation) and finally you bank around the resulting Z axis.

RPY is more popular among robotics.

As you can see: How you order the rotation also defines which angles you need to use for getting into an intended attitude.

Every such rotation can be expressed by a rotation matrix. When you chain those matrixes as factor into a multiplication, you get a single projection matrix:

[math]M_{PYR}=M_{roll} \cdot M_{yaw} \cdot M_{pitch}[/math]
and thus:

http://en.wikipedia.org/wiki/Tait–Bryan_angles#Rotation_matrix
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Every such rotation can be expressed by a rotation matrix. When you chain those matrixes as factor into a multiplication, you get a single projection matrix:

I'm with you up to this point.

The question is how do I find the the set of rotations that will align matrix "a" with matrix "b" and translate them into PYR values?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I'm with you up to this point.

The question is how do I find the the set of rotations that will align matrix "a" with matrix "b" and translate them into PYR values?

That is what I mean with "solve".

lets say you have a matrix A with your current principal axes of the spacecraft as column vectors. Matrix B is the rotation matrix by the model that you selected.

If you declare A = B, every component of the matrix A and matrix B are equated.

Now, you could just pick those component equations which are just sin(something) or cos(something else), but... those functions are symmetric and their inverse functions are not defined for the full circle (like 0° to 180° or -90° to +90°).

So, you better try to select pairs of components which you can solve by an atan2() function, which works for the full circle (-180° to +180°).

How you do that is now a matter of what you want to use. PYR? RPY? something else? This selection of the axis order defines what solutions you will get for your angles. Usually, you will have one angle as asin() or acos() of a single component and two defined by atan2() of two components.
 
Last edited:

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Ok so if vector A is my spacecraft's principal axes in ecliptic frame, is B the principal axes of my reference frame (in the ecliptic frame), or is it the conversion matrix for my reference frame to ecliptic?

I'm also confused about your component operations.

Aren't the components in this case vectors?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Ok so if vector A is my spacecraft's principal axes in ecliptic frame, is B the principal axes of my reference frame (in the ecliptic frame), or is it the conversion matrix for my reference frame to ecliptic?

I'm also confused about your component operations.

Aren't the components in this case vectors?

Well...think of a matrix as an array. Every entry in the two dimensional array called matrix is called "component". A vector can be a component as well, but generally, because it is mildly confusing, we should stay away from it and call such things "column vector" or "row vector".

Every component can be anything. In our case, we have concrete real numbers in matrix A (measurements of our navigation system) and formulas in matrix B (model of our rotation)

Now, if we equate every matrix, it also means every component in the matrix must be equal. if A[1][1] is 0 so must be B[1][1], etc.

If we generalize things, we get to a form like:

a11 = sin(pitch) * cos(yaw) (1)
a21 = cos(pitch) * cos(yaw) (2)

if we divide equation (1) by equation (2) we get.

a11/a21 = sin(pitch)/cos(pitch) = tan(pitch) (3)

This is now the general version... one math fits all. Now, we are lazy... if you know which order of rotations you use, you can already find complete formulas for such calculations in the www. :lol:

For example in the german industry norm DIN 9300.
 

SiameseCat

Addon Developer
Addon Developer
Joined
Feb 9, 2008
Messages
1,699
Reaction score
1
Points
0
Location
Ontario
Ok so if vector A is my spacecraft's principal axes in ecliptic frame, is B the principal axes of my reference frame (in the ecliptic frame), or is it the conversion matrix for my reference frame to ecliptic?

I'm also confused about your component operations.

Aren't the components in this case vectors?
If I understand you correctly, you want to find the rotation matrix R so that A = BR (i.e. R is the rotation from frame B (the ref frame) to frame A):
[math] A = B [/math]
[math] B^{-1}A = B^{-1}BR [/math]
[math] B^{-1}A = R [/math]Since [math] B^{-1} = B^T [/math], this means that [math] R = B^T A[/math]. Now all you have to do is find the PYR angles corresponding to the rotation matrix R.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
Yes but it is the actual doing that is presenting a problem as apparently I am missing a step. The functions sine cosine and tangent do not take vectors as arguments.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Yes but it is the actual doing that is presenting a problem as apparently I am missing a step. The functions sine cosine and tangent do not take vectors as arguments.

No, the vectors are put into the matrix:

Xx|Yx|Zx
Xy|Yy|Zy
Xz|Yz|Zz

Like that: Every column in the matrix is one of the principle axes of your spacecraft converted into world coordinates.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
No, the vectors are put into the matrix:

Xx|Yx|Zx
Xy|Yy|Zy
Xz|Yz|Zz

Like that: Every column in the matrix is one of the principle axes of your spacecraft converted into world coordinates.

:facepalm:

Ok that explains half of the confusion.

so basically what I need to do is...

Get my reference frame.
Get the conversion matrix for my frame to global frame.
Multiply my rotation matrix (AKA vessel::GetRotationMatrix ()) by that.
THEN calculate PYR?


Nope that wont work because as global orientation approaches 0 so will the above.

I'm still confused.

At this point I'm thinking that I need to do this as a projection problem (project vessel's axes onto my notional horizon plane and work from there) or treat it as a two-stage rotation problem, rotate matrix around an arbitrary axis until one of the axes match and then rotate around that axis untill the other two are aligned, but there has to be a more elegant solution than that.

---------- Post added at 13:11 ---------- Previous post was at 08:44 ----------

Ok I've taken a nap and gotten some coffee.

To get a rotation frame to align 2 matrices I figure the following should work.

Matrix A = reference axes.
Matrix B = direction of the vessel's X Y and Z axes
Matrix C = Rotation Matrix.

Get acos (dotp (Ax, Bx))

if angle = 0 skip to next axis

otherwise C = Identity matrix rotated by angle around the cross product of Ax and Bx.

Repeat for Y axis.

Does anyone have a quicker, or computationally simpler way?
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,638
Reaction score
2,353
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
When I had some more caffeine, I can try giving you a solution for RPY in right-handed coordinates. As you can imagine: In left-handed coordinates, like in Orbiter, you would need to change some signs. I doubt I can today calculate this for you, I am pretty empty on battery now. :rofl:
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
I'm just frustrated at this point.

I would expect this to be a reasonably simple, or at the very least, a "pre-solved" problem. But no. I don't even give a :censored: about right vs. left handed coordinates, if I have one I know how to get the other.

On the bright-side I have read some interesting articles on inverse kinematics while looking for an answer.
 
Top