🔒 Locked
simple trig problem
Advertisement
Original Post
I have an object in space and all I want to do is set its pitch/yaw/roll to be the angles that match its current velocity.
i can move the object around using different velocity values, however i am unsure of how to determine the pitch/yaw/roll angles so that i can re-orient the object to face the direction its moving in.
im thinking perhaps i should measure the delta between the last velocity and the new one, and then calc the angles with atan or something like that, but i have tried many things and nothing seems to work :[
thanks very much for your time!
synja
If the object is to be aligned with the velocity direction, then you can determine pitch and yaw from the velocity direction. But roll is independent of that direction, since roll is defined about the axis that would be aligned with the velocity. Thus, you cannot determine roll based purely on velocity direction. You have to have some other criteria for determining roll.
However, in your case, I see no need at all that you calculate the pitch and yaw angles. As I see it, you were going to use roll, pitch, and yaw to create a transformation matrix. You don't need the pitch and yaw angles to create that matrix. You may need roll angle, but lets cover the basic orientation of the object first----the pitch and yaw effect.
If you know the velocity in world space, and if you specify the orientation of the object in world space, then you really don't have to apply pitch and yaw as angles. That info is actually embedded in the velocity direction, and so you can just stuff a normalized version of that vector into the transformation matrix directly. So, say the x axis of the object is pointing towards the front of the object---meaning it is the x axis you want to align with velocity. And say your velocity direction is (vdx, vdy, vdz). Then your transformation matrix for the object would be (3x3 - orientation only - add a row and column to add translation/position):
The first column of that matrix is just your velocity direction vector. The second and third columns represent the object local y and z axes, respectively. These columns are functions of your roll angle. I won't talk about that for now. But I will prove that this transformation matrix *will* properly orient your object in the velocity direction. The idea is this. You want the x direction of the object, given by (1,0,0) in object space, to be transformed to (vdx, vdy, vdz) in world space----your velocity direction. To do this, just multiply R times your object x direction (written as a column vector). Just like this:
world_space_x = R * object_space_x
Or,
Multiply this out and you will get:
You will also see that the object local y axis (0,1,0) transforms to (yx, yy, yz), and the object local z axis transforms to (zx, zy, zz). So really the columns of the rotation matrix R just represent the directions you want your local object axis to rotate into. No need to deal with pitch and yaw angles at all if you already have the final direction of interest as a vector. Those angles are merely used to find the direction if you do not already know it.
I would like to add a final note. If you are doing any aerodynamic calculations, say for a flight simulator of some sort, then you may very well need pitch and yaw angles for the aerodynamics calculations. But I'm not going to tell you how to calculate those angles. If you need them for this purpose, we can continue the discussion.
Please let me know if you understand this discussion, and if it is helpful/applicable to your problem. Then, if you need further assistance, we can move on to dealing with the roll angle. It may be that you do want to use a roll angle to determine the world space y and z axes, although there are approaches to that as well that do not require an angle.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
[edited by - grhodes_at_work on April 11, 2002 5:41:46 PM]
However, in your case, I see no need at all that you calculate the pitch and yaw angles. As I see it, you were going to use roll, pitch, and yaw to create a transformation matrix. You don't need the pitch and yaw angles to create that matrix. You may need roll angle, but lets cover the basic orientation of the object first----the pitch and yaw effect.
If you know the velocity in world space, and if you specify the orientation of the object in world space, then you really don't have to apply pitch and yaw as angles. That info is actually embedded in the velocity direction, and so you can just stuff a normalized version of that vector into the transformation matrix directly. So, say the x axis of the object is pointing towards the front of the object---meaning it is the x axis you want to align with velocity. And say your velocity direction is (vdx, vdy, vdz). Then your transformation matrix for the object would be (3x3 - orientation only - add a row and column to add translation/position):
[ vdx yx zx]
R = | vdy yy zy|
[ vdz yz zz]
The first column of that matrix is just your velocity direction vector. The second and third columns represent the object local y and z axes, respectively. These columns are functions of your roll angle. I won't talk about that for now. But I will prove that this transformation matrix *will* properly orient your object in the velocity direction. The idea is this. You want the x direction of the object, given by (1,0,0) in object space, to be transformed to (vdx, vdy, vdz) in world space----your velocity direction. To do this, just multiply R times your object x direction (written as a column vector). Just like this:
world_space_x = R * object_space_x
Or,
[ vdx yx zx] [1]
world_space_x = | vdy yy zy| * |0|
[ vdz yz zz] [0]
Multiply this out and you will get:
[vdx]
world_space_x = |vdy|
[vdz]
You will also see that the object local y axis (0,1,0) transforms to (yx, yy, yz), and the object local z axis transforms to (zx, zy, zz). So really the columns of the rotation matrix R just represent the directions you want your local object axis to rotate into. No need to deal with pitch and yaw angles at all if you already have the final direction of interest as a vector. Those angles are merely used to find the direction if you do not already know it.
I would like to add a final note. If you are doing any aerodynamic calculations, say for a flight simulator of some sort, then you may very well need pitch and yaw angles for the aerodynamics calculations. But I'm not going to tell you how to calculate those angles. If you need them for this purpose, we can continue the discussion.
Please let me know if you understand this discussion, and if it is helpful/applicable to your problem. Then, if you need further assistance, we can move on to dealing with the roll angle. It may be that you do want to use a roll angle to determine the world space y and z axes, although there are approaches to that as well that do not require an angle.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
[edited by - grhodes_at_work on April 11, 2002 5:41:46 PM]
quote:
Original post by Anonymous Poster
Wouldn''t simply calculating the normal and multiplying each normal (of the velocity) by 2PI give you the correct radian?
Are you trying to suggest one way to calculate the roll angle? Please expand on your comment. It just doesn''t make sense as you wrote it here. For example, when you say "multiplying each normal (of the velocity) by 2PI," what do you mean by "each normal"? There are an infinite number of normals to a vector in 3D space. You really need just one normal to get roll angle. Do you have a specific approach to downselect to that one normal? Second, when you multiply a vector (the normal) by 2PI, you get a vector of length 2PI. That is not an angular measurement in radians. The "2PI" is an angle, equivalent to 360 degrees! Are you saying that roll angle is always 360 degrees? Well, you could say that, but no need to calculate it in that case.
So, I think you have something workable in mind, but you just haven''t described it well. I''m just looking for a better description. And, I would prefer that you register and login instead of posting anonymously.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
I''ve looked long and hard at your explanation, and i think i can visualize it... so let me try and put into words what im thinking and hopefully you can tell me if ive got the right mental model...
i need to keep 3 reference vectors in mind...
right vector - one that points to the right, relative to the objects current direction.
up vector - one that points directly ''up'' , relative to the objects direction
forward vector - one that points ''out'' in front of the objects direction
now i assume after I translate the objects position based on velocity, i need to rotate the object about these three axes.... That I think I can manage, however, how do I structure the final transformation matrix to multiply the object against to achieve this effect?
also, how do i adjust these three reference vectors to always be relative to the velocity''s direction? I know the right vector would be the Normal of the front/up vector plane, and so on and so forth, but putting all this into matrices is where i get lost
thanks so much for your help
synja
i need to keep 3 reference vectors in mind...
right vector - one that points to the right, relative to the objects current direction.
up vector - one that points directly ''up'' , relative to the objects direction
forward vector - one that points ''out'' in front of the objects direction
now i assume after I translate the objects position based on velocity, i need to rotate the object about these three axes.... That I think I can manage, however, how do I structure the final transformation matrix to multiply the object against to achieve this effect?
also, how do i adjust these three reference vectors to always be relative to the velocity''s direction? I know the right vector would be the Normal of the front/up vector plane, and so on and so forth, but putting all this into matrices is where i get lost
thanks so much for your help
synja
quote:
Original post by Anonymous Poster
N = GetNormal(V);
YPR.Yaw = N.x*3.1415;
YPR.Pitch = N.y*3.1415;
YPR.Roll = N.z*3.1415;
Thanks for the clarification! Unfortunately, its the wrong answer,
I'll try to present an example of the failure of your approach. First, we need some definitions. The definition of pitch is a rotation about the local y axis. Definition of yaw is rotation about local z. Definition of roll is rotation about local x. There can be slight variations on this, but that's basically it.
Let's do a mind experiment. I'll set up the situation. Our global x axis points to the front of the world, global y axis points to the left side of the world, and global z axis points towards the top of the world. The object is initially aligned with this so the objects's local axes are the same as the global axes. The object's local x axis points toward the front of the object. The object is moving forward when it moves in the direction of that local x axis. The velocity vector points straight up, towards positive global z---top of the world. We would like to reorient the object so that its facing in the velocity direction, i.e., the object's local x axis points towards positive global z---top of the world. This way, when we move forward, we will be moving upwards, towards positive global z. Your approach would yield this result:
N = (0, 0, 1);
Yaw = 0 * PI = 0;
Pitch = 0 * PI = 0;
Roll = 1 * PI = 3.1415;
With your result, there is no yaw, and no pitch, only roll. So we roll the object by PI radians, 180 degrees about the local x axis. That causes the local z to be flipped to be pointing straight down (negative global z), and local y is now pointing towards the right (negative global y). The object is just rolled upside down. The local x axis remains unchanged, and so your approach does not yield the desired result. Remember, we wanted local z to be pointing straight up, towards positive global z---top of the world.
The real values for yaw, pitch, and roll in this case are:
yaw = 0;
roll = 0;
pitch = -PI/2; // (-90 degrees)
This causes the object to rotate by -90 degrees about the positive local y axis (which is to the left side of the world until we change it), which causes the front of the object to rotate up to positive global z---top of the world. Also, the local y axis still points to the left side of the world. And local z now points to the rear, negative global x---back of the world.
I'd also like to note that you're misusing the word "normal." A "normal" vector to the velocity vector is perpendicular to the velocity vector. But your GetNormal() method does not compute a vector that is perpendicular to the velocity vector. It merely computes a unit length vector in the direction of the velocity vector. That unit length vector can properly be referred to as "unit vector", "velocity direction", or "normalized velocity vector." I think you meant to call it "normalized vector," and your method would be better named GetNormalizedVector. When you use the word "normal," you imply that you are calculating something perpendicular to the given vector or plane. And the misuse of the word leads to confusion of your approach.
One of these days I'm going to have to set up a way to post figures to these forums, because this really deserves a picture or two.
I hope this does help you understand the concept of roll, pitch, and yaw a bit better. Please consider this to be educational, constructive criticism,
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
[edited by - grhodes_at_work on April 12, 2002 1:20:52 PM]
I did try using atan but I dont think its really the proper way to go.
I understand that the yaw is the velocity vector's x and z components
I know simple trig from 7th grade...
Some Old Hippy... Caught Another Hippy... Tripping On Acid
(yes my 7th grade math teacher taught me that, funny i still remember it today
)
And the same goes for the other 2 angles (using yz, and xy)
However, isnt there some way to accomplish these calculations just by multiplying matrices?
If I have a change in velocity, thats going to require recalcing the reference axes (Up/Right/Forward) .. how do i do this relative to the delta V?
for instance.. say my first velocity is in the Z direction (0, 0, 1) .. I go 5 units this way.. then I change to (1, 0, 1) .. mentally I made a 45 degree turn to the right, still heading in Z axis but also moving along X as well.. my right and forward references axes change at this point, and i would like to recalc them based on the new velocity...
so my ultimate question is how to recalc the reference axes based on the change of velocity. Because once I have these new reference axes, rotating about them is no prob!
thanks
synja
[edited by - synja on April 12, 2002 3:26:04 PM]
[edited by - synja on April 12, 2002 4:04:00 PM]
I understand that the yaw is the velocity vector's x and z components
I know simple trig from 7th grade...
Some Old Hippy... Caught Another Hippy... Tripping On Acid
(yes my 7th grade math teacher taught me that, funny i still remember it today
And the same goes for the other 2 angles (using yz, and xy)
However, isnt there some way to accomplish these calculations just by multiplying matrices?
If I have a change in velocity, thats going to require recalcing the reference axes (Up/Right/Forward) .. how do i do this relative to the delta V?
for instance.. say my first velocity is in the Z direction (0, 0, 1) .. I go 5 units this way.. then I change to (1, 0, 1) .. mentally I made a 45 degree turn to the right, still heading in Z axis but also moving along X as well.. my right and forward references axes change at this point, and i would like to recalc them based on the new velocity...
so my ultimate question is how to recalc the reference axes based on the change of velocity. Because once I have these new reference axes, rotating about them is no prob!
thanks
synja
[edited by - synja on April 12, 2002 3:26:04 PM]
[edited by - synja on April 12, 2002 4:04:00 PM]
quote:
Original post by Anonymous Poster
Sorry, I didn't follow my logic out very far to realize that I'm only returning the angle at which it has been rotated, so you'd still have to get the angle.
You're getting closer here,
alpha = acos(N.x); // angle measured from global x axis
beta = acos(N.y); // angle measured from global y axis
phi = acos(N.z); // angle measured from global z axis
Your multiplication by PI in your original two posts are still not based on any geometric reasoning. I think you realized this already.
I see what you're trying to do with the atan2 in your latest post. You do get values that are like roll, pitch, and yaw. And I can see that you could possibly use them this way. But they really are not true roll, pitch, and yaw. The problem is that your angles are based on the orientation of one vector. But roll, pitch, and yaw are actually based on an entire coordinate system---three vectors. You cannot find true roll, pitch, and yaw given just one vector and no reference planes. You could use your atan2 approach to get the three angles, but you would still need three vectors to do it, and you'd end up using components of all three vectors in your three atan2() calls. Does this make sense? Maybe not without a picture, damnit!
But at least the idea of what you wanted to do makes geometric sense now. Ah, progress!
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
[edited by - grhodes_at_work on April 12, 2002 5:28:58 PM]
quote:
Original post by synja
so my ultimate question is how to recalc the reference axes based on the change of velocity. Because once I have these new reference axes, rotating about them is no prob!
I''m wondering if my original response was useful? I still maintain that given your new absolute velocity direction, one column of the rotation matrix is known without needing to do a rotation. The yaw and pitch angles are embedded in that column and the only further rotation you need is roll. And you don''t necessarily need to calculate a roll angle to accomplish the rolling action.
You can find a roll effect (but not the only possible roll effect)----which will be accomplished by filling out columns 2 and 3 of the rotation matrix---using the triangle that is formed using two vectors: the previous velocity vector and the new velocity vector. If you take the normal to the cross product on the old velocity direction and the new velocity direction to be your y axis, then that will give you the second column of the matrix. And the third column would be the cross product of the new velocity direction and the calculated y axis. As above, this doesn''t require any explicit rotation angles at all. Everything is calculated using vectors. The roll that you get using this approach may not be the roll that you desire. Of course, if there is no change in velocity direction, then you do not need to recalculate the rotation matrix for this frame....
I find that roll, yaw, and pitch are most useful if you are using those as your simulation variables. That is, if you explicitly change roll, yaw, and pitch every frame and need to convert those into a transformation matrix. If you''re changing direction vectors, then there is rarely a need to actually calculate the angles!
Please let me know if this info is helpful. You should perhaps experiment with my approach.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Hi Bill,
Actually, I didn''t state my case precisely enough. Your approach does in fact orient the object''s x axis correctly towards the velocity direction. But your approach is not guaranteed to orient the other two axes (object y and z axes) in a reasonable way. Your roll angle calculation will lead to gimbal lock, which is not desirable. The problem is that you''re trying to calculate the orientation of an entire object coordinate system from one vector in that coordinate system. There just aren''t enough degrees of freedom without dealing with additional axes or planes. I try to give a bit more explanation on this in the third paragraph. But first, a clarification and apology!
Actually I did make an error in my statement, and your new post made me think about that,
. Your atan2 calculations for pitch and yaw are good ----not exactly the same as mine, but a valid interpretation of yaw and pitch. Your angles are based on rotations about global axes, while mine are based on rotations about local axes. In any case, your yaw/pitch angles are good and usable. I apologize for not being quite careful enough in my other post,
.
HOWEVER, yaw and pitch only correctly orient one vector of the object----the x axis pointing towards the front of the object. The object can still roll 360 degrees about its x axis while continuing to point in the correct direction. You need a roll angle (or two additional vectors to fill out the rotation matrix). And it is your roll angle that is the problem here. In some cases, your atan2-based roll angle may look reasonable, but it is not really a true roll angle and you will have gimbal lock problems.
Yes, as long as you are willing to accept the gimbal lock,
.
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
quote:
Original post by Anonymous Poster
So, your saying that my Atan2 won''t work.
Actually, I didn''t state my case precisely enough. Your approach does in fact orient the object''s x axis correctly towards the velocity direction. But your approach is not guaranteed to orient the other two axes (object y and z axes) in a reasonable way. Your roll angle calculation will lead to gimbal lock, which is not desirable. The problem is that you''re trying to calculate the orientation of an entire object coordinate system from one vector in that coordinate system. There just aren''t enough degrees of freedom without dealing with additional axes or planes. I try to give a bit more explanation on this in the third paragraph. But first, a clarification and apology!
Actually I did make an error in my statement, and your new post made me think about that,
HOWEVER, yaw and pitch only correctly orient one vector of the object----the x axis pointing towards the front of the object. The object can still roll 360 degrees about its x axis while continuing to point in the correct direction. You need a roll angle (or two additional vectors to fill out the rotation matrix). And it is your roll angle that is the problem here. In some cases, your atan2-based roll angle may look reasonable, but it is not really a true roll angle and you will have gimbal lock problems.
quote:
Original post by Anonymous Poster If the atan2 function works, it will probably be the best one to use, as you won''t have to do a dot product, sqrt and 3 acos... instead you need only do 3 atans.
Yes, as long as you are willing to accept the gimbal lock,
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement