Jump to content
  • Advertisement
Sign in to follow this  
donvreug

Determining rotation angles expressed in a different rotation system

This topic is 1334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new to graphics rotations and am trying to solve the following problem. 

 

I have an initial rotation system defined by: The rotation (or the direction) is defined by 3 successive rotations around Z, then Y, then X, all defined positive counter-clockwise from East to North (+Z+Y+X). Angles are bounded by -180 and +180 deg.

 

And I'd like to determine the rotation angles in a second system defined by: The rotation (or the direction) is defined by 3 successive rotations around Z, then X, then Z again, the first one being defined positive clockwise from North to East (Azimuth), the second one counter-clockwise from East to North and the third one clockwise from East to North (A+X-Z). Angles are bounded by 0 and +360 deg. When this convention is used to define a plane, the last angle defines a reference direction. The two first angles are equivalent to (azimuth, dip).

 

I presume this may be accomplished by a change of basis but I am still trying to come to grips with how to do that.

 

So if I enter in the first system rotation angles of 90, 0, -20 how do I find these angles expressed in the second system?

 

I am using DirectX/Direct3D.

 

Thanks for your help.

Share this post


Link to post
Share on other sites
Advertisement

Welcome to gamedev!

 

As it is with many reputable sites with active forums, posting questions related to homework is against site policy. If your question is not, in fact, a homework problem, you'll likely get much better responses to your question if you can describe the practical situation with regard to D3D11 graphics you're trying to program.

Share this post


Link to post
Share on other sites

Thanks for the response.  This is not a homework question.  It's been quite a while since I was at school. smile.png  

 

The problem is work related. We use a number of software applications that each use their own rotation convention.  I am writing an application that will display the rotation angles for each software application on the one form, together with visualisation of the rotation.

 

I posted my question on this forum because it appeared to have people who were discussing graphics programming at a deep mathematical and technical level, as opposed to MSDN forums which don't have much deep graphics programming discussions.

 

I have found many examples of rotating points or vectors around axes but few changing the rotation system.  Those that I have found discuss the maths but don't provide coded examples.

 

I was hoping to gain insight into how to approach such problems and the algorithms employed to resolve them, as well as practical examples.

 

I have a code snippet (C# and Direct3D) that goes some way to solving the issue in 2D but is not quite there in 3D.

                // initialise matrices
                Matrix u1, v1, w1, u2, v2, w2, base1, base2, invert2, cob;

                // gslib: A-Y+X
                u1 = Matrix.RotationZ(deg2rad(90.0 - rot1)); //  A
                v1 = Matrix.RotationY(deg2rad(-rot2));       // -Y
                w1 = Matrix.RotationX(deg2rad(rot3));        // +X
                base1 = Matrix.Multiply(Matrix.Multiply(w1, v1), u1);

                // initialise vectors
                Vector4 r1, r2;

                // assign values to v1
                //r1.X = deg2rad(rot1);
                //r1.Y = deg2rad(rot2);
                //r1.Z = deg2rad(rot3);
                //r1.W = 0;

                r1.X = (float)Math.Atan2((double)base1.M11, (double)base1.M12);  // looks ok
                r1.Y = (float)Math.Atan2((double)base1.M21, (double)base1.M22);  // wrong
                r1.Z = (float)Math.Asin((double)base1.M23);  // wrong
                r1.W = (float)Math.Asin((double)base1.M44);  // ?

                // geologist plane: A+X-Z
                u2 = Matrix.RotationZ(deg2rad(90 - rot1));
                v2 = Matrix.RotationX(deg2rad(rot2));
                w2 = Matrix.RotationZ(deg2rad(-rot3));
                base2 = Matrix.Multiply(Matrix.Multiply(w2, v2), u2);

                // invert matrix
                invert2 = Matrix.Invert(base2);

                // multiply source matrix with inverted matrix
                cob = Matrix.Multiply(invert2, base1);

                // multiply cob with v1 to get v2
                r2 = Vector4.Transform(r1, cob);

                // initialise vector components
                double i, j, k;

                // assign vector components
                i = rad2deg((double)r2.X);
                j = rad2deg((double)r2.Y);
                k = rad2deg((double)r2.Z);

                //i = (i < 0) ? (i + 360) % 360 : i;
                i = (i + 360) % 360;

                // return vector components
                return new IsatisGeoPlane(i, j, k);

I am not even sure this is the right way to go about solving the problem.

 

So if anyone has insight into how to go about this or can see where I am going wrong I'd be grateful for the assistance.

Share this post


Link to post
Share on other sites

More likely due to my inadequacies than yours, I'm not sure I fully understand the problem. However, making a guess:

 

It appears that one system uses right-hand rule coordinates/rotations, and the other left-hand.

 

Noting that it (sort-of) appears like you're attempting to do this: a common method for doing matrix calculations in one system, and transforming the results into another system is:

 

Mat-result = Mat-From-Sys1-To-Sys2 * Mat-manipulate-Sys2 * inverse(Mat-From-Sys1-To-Sys2)

 

I.e., Mat-From-Sys1-To-Sys2- is a matrix which transforms from System 1 to System2. Mat-manipulate-Sys2 is the desired transformations in System2. And inverse(...) is the matrix inverse of Mat-From-Sys1-To-Sys2, i.e., transform from Sys2 to Sys1.

 

E.g., if Mat-From-Sys1-To-Sys2 is set to a transformation from left-hand to right-hand, and Mat-manipulate-Sys2 is set to the desired transformations** in the right-hand system -

 

** transformations in the RH system will be using the rules for that system.

 

Vector V_LH_1 = ...; // position or direction in LH system

Vector V_LH_2 = V_LH_1 * Mat_LHtoRH * Mat_RH_manipulate * inverse( Mat_LHtoRH );

 

Is that generally in the direction (pun intended) of what you're trying to do?

Edited by Buckeye

Share this post


Link to post
Share on other sites

Yes that is what I am attempting to do.

 

I suspect where I am going wrong is in defining the matrix from system 1 to system 2.

 

So ignoring my code snippet...

 

If system 1 is defined by 3 successive rotations around Z, then Y, then X, all defined positive counter-clockwise from East to North (+Z+Y+X). Angles are bounded by -180 and +180 degrees.

 

and system 2 is defined by 3 successive rotations around Z, then X, then Z again, the first one being defined positive clockwise from North to East (Azimuth), the second one counter-clockwise from East to North and the third one clockwise from East to North (A+X-Z). The first angle is bounded by 0 and +360 degrees. The second and third are bounded by -180 and +180 degrees.

 

How do I go about finding the transformation matrix?

Share this post


Link to post
Share on other sites

If system 1 is defined by 3 successive rotations around Z, then Y, then X, ...

 

First, I'm afraid it's still not quite clear what you mean by defining a "system" by "rotations." I.e., rotations must be defined with respect to a fixed reference frame.

 

I think I may be beginning to understand the situation - maybe. Is the problem situation something like the following:

 

1. Define 3 vectors A, B, C in System 1 such that A = (1, 0, 0), B = (0, 1, 0), C = (0, 0, 1) - each vector initially coincident with one of the 3 axes.

2. Rotate A and B about the System 1 Z axis (at this point, the same as rotating A and B about C.)

3. Now.. QUESTION: the next rotation you describe as "about Y" - is that rotation about the System 1 Y axis, or about vector B (which previously was coincident with System 1 Y axis)?

4. Rotate "about X" - similar question - is that a rotation about the System 1 X axis, or about vector A (whatever it's current orientation)?

 

In any case, once the rotations related to System 1 (whatever they may be)  have been made, there remains 3 orthogonal vectors A, B, C, and they can be used as a "coordinate system" - i.e., a point or vector in System 1 can be defined as a*A + b*B + c*C.

 

Is then part of your task is to determine those coefficients a, b and c? That is, determine the point/vector (a, b, c) in the "system" defined by vectors A, B, C?

 

EDIT: FYI, may be useful info, a common graphics transformation between a right-handed system and left-handed system is, for example:

 

Given a right-handed system with Z-up, and a left-handed system with Y-up, create a matrix which scales along Z by -1, and rotates about X (right-hand rotation) by PI/2 (or left-hand rotation by -PI/2).

 

Mat-transform = Mat-scale( 0, 0, -1 ) * Mat-Rotate-By-Axis-Angle( [1, 0, 0], PI/2 ); // from RH Z-up to LH Y-up

Point-in-LH-system = Point-in-RH-system * Mat-transform;

Point-in-RH-system = Point-in-LH-system * inverse( Mat-transform );

Edited by Buckeye

Share this post


Link to post
Share on other sites

I apologise if I am not using the correct terminology.  I am talking about a coordinate system defined by 3 orthogonal vectors X, Y, Z and an origin.  Z in all cases is up, Y is North and X is East.  The origin is shared by each coordinate system.  What I have available to me are descriptions of the rotation conventions used in each coordinate system and angles of rotation about each axes which define a reference plane.

 

What I want to do is given the rotation angles in one coordinate system, determine the rotation angles of the second coordinate system that defines the same reference plane.

 

Successive rotations occur around the current axis orientation. So if we initially have X, Y, Z axes.  The first rotation is about Z.  So we now have X1, Y1, Z1 (Z1 = Z).  The second rotation is about Y1. We now have X2, Y2, Z2 (Y2 = Y1).  The third rotation is about X2.  So the final axes will be X3, Y3, Z3 (X3 = X2).

 

If I could figure out how to post an image I would.  I think that would make it clear.

Edited by donvreug

Share this post


Link to post
Share on other sites

Yeah, terminology is a problem. An image would help. I don't know if you've been a member long to post an image. However, when you post a reply, below and to the right of the edit box should be a button "More Reply Options" which takes you to a full editor. That editor has the option to attach files. If that's not available to you, you can also upload an image to a site somewhere (pastebin, etc.) and post a link to it in your reply here.

 

An image may help. Some things that aren't clear that the image may resolve (or further explanation on your part):

 


I am talking about a coordinate system defined by 3 orthogonal vectors X, Y, Z and an origin. Z in all cases is up, Y is North and X is East. The origin is shared by each coordinate system.

 

You describe one set of axes, so I'm a bit confused then by the mention of "each coordinate system" following the description, and elsewhere "...the second coordinate system..." Are you talking about, perhaps, one coordinate system with two sets of rotation "rules" or "conventions" or "limitations" or "operations?"

 

Here's hoping you can get an image available. It sounds like an interesting problem.

Share this post


Link to post
Share on other sites

Thanks for the tip on adding files.

 

The first two images are from one of the software applications we use.

 

This first image shows the rotations defined in the "mathematician" convention, i.e. +Z +Y +X, all positive counter-clockwise.

 

The second image shows the rotations defined by the "geologist plane" convention, i.e. A +X -Z, The first rotation being defined positive clockwise from North to East (Azimuth), the second one positive counter-clockwise about X and the third one positive clockwise about Z (A+X-Z).

 

The third image is the application I am writing.  It shows the same rotation angles as the mathematician convention, but ignore all the other angles as they are not correct yet.

 

Your point about whether they are in fact just one coordinate system may be valid, or is a new coordinate system defined by the resulting rotations? 

 

Share this post


Link to post
Share on other sites

Glad you got the images posted. Good for you having figured that out. They do provide a better basis than your description. For instance, it appears that whatever is being done, each method (mathematician, geologist...) is applied to a fixed coordinate system.

 

However, without further explanation, it's not clear what the intent of the application is - that is, what result/product/data it should produce. Your post implies you want to convert a data set, generated with a specific set of constraints, to another data set, the results of which fall within another specific set of constraints. So, what "data set" means mathematically needs to be defined.

 

From a math standpoint, concatenating 3 rotations, using matrices or quaternions, can obviously be done**. A description of how the final matrix or quaternion will be applied would help a lot. That is, once such a matrix or quaternion is constructed, how will it be used? Something like "If I'm facing east, what direction will I be facing after the rotations?" ??

 

** Things like MatFromAxisAngle(...) and QuatFromAxisAngle(...)

 

Disclaimer regarding me personally: I'm more of a matrix guy, than quaternion, and intuition tells me the rotations you're talking about are more easily handled with quats than mats.

 

Questions that may help:

 

A. What is the intent (the end result) of the application, in words? That will help put things into context. Maybe something like "We're looking for different ways to determine the direction to a star from angle measurements at different places on the Earth." Or "We're looking for different ways to determine the direction of the magnetic field ..."

 

B. In a bit more detail, what is the intent of setting rotations? After 3 angles have been entered, what information results? If you can describe that in both words and exact mathematical terms, that would help a lot. Maybe something like "If a mathematician measures some angles (angles of what?), we can provide angles in terms a geologist will understand."

 

As it appears from the images that the results from each method (mathematician, geologist, etc.) are with respect to the same fixed coordinate system. That's good. The bad part will be determining the algorithm to convert the results from one method to another, given the constraints. It may have to be iterative, and the algorithm may have to be specific with respect to which 2 methods are chosen as From and To.

 

Note: this post appears to be more of a "Math and Physics" forum topic, than "Graphics Programming and Theory." I.e., the math/physics gurus here on gamedev may pay more attention to the former than the latter.

 

I.e., just guessing, but is the following close to what you're trying to do?

 

1. Generate a matrix Ma using method A.

2. Given Ma, determine M1, M2, M3 such that:

 

Ma = M1 * M2 * M3;

 

3. Further, M1, M2, M3 must be based on angles about specific axes, and those angles must meet specific constraints from method B.

4. Determine, as the desired result, the 3 angles which can be applied to method B.

 

More generally, to avoid selecting a method for solution before the problem is defined,

 

1. Given 3 angles applicable to method A, determine 3 angles applicable to method B, such that both methods produce the same results.

 

N.B., "results" needs to be defined! <-- The crux of the matter

Edited by Buckeye

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!