# Using AnyKinRotational to get the Euler angles

I am getting different results when trying to calculate the Euler angles when
using
AnyKinRotational, type = RotAxesAngles.

Below is some code that I wrote to test this, but what I am trying to do is:
define three angles : {1.5103, 0.2263, 2.3537};
construct an original rotation matrix using those angles
calculate three angles (they may not be the same as the original three) from the
rotation
matrix
calculate a new rotation matrix.

the original rotation matrix should be the same as the new rotation
matrix…this is not
happening for the sequence I have defined:

Thanks for your help. Am I doing something wrong?

-David

Here is the code:

// Todo: Write a small description of your model here
//Load and run set Initial conditions.
//It will fail, but not before it calculates the values of
//tempMatrix, and tempMatric_calc
//
//I think they should be the same…but they are not.
//The tempAngles and tempAngles_calc should be the same and seem to be
//different by a factor of 180 (pi)…when if they are different , I think they
should
//be by a factor of 360 degrees (2*pi)

//Thoughts? Am I doing something wrong here?

Main = {

// The actual body model goes in this folder
AnyFolder MyModel = {

`````` // Global Reference Frame
AnyFixedRefFrame GlobalRef = {

// Todo: Add points for grounding of the model here

};  // Global reference frame

// Todo. Add the model elements such as
//       segments, joints, and muscles here.

AnyVector tempAngles = {1.5103, 0.2263, 2.3537};

AnyMatrix tempMatrix = RotMat( tempAngles[0] ,z)*
``````

RotMat( tempAngles[1] ,y)*
RotMat( tempAngles[2] ,x);

`````` AnySeg tempSeg =
{
//r0 = {0, 0, 0};
//rDot0 = {0, 0, 0};
Axes0 = .tempMatrix;
//omega0 = {0, 0, 0};
Mass = 0;
Jii = {0, 0, 0};
//Jij = {0, 0, 0};
//sCoM = {0, 0, 0};
};

AnyKinRotational tempAngles_calc ={

AnyRefFrame &ref1 = .GlobalRef;
AnySeg &ref2 = .tempSeg;
Type=RotAxesAngles;

Axis1 = z;
Axis2 = y;
Axis3 = x;
//finished DW added code
``````

};

``````       AnyMatrix tempMatrix_calc = RotMat( tempAngles_calc.Pos[0] ,z)*
``````

RotMat( tempAngles_calc.Pos[1] ,y)*
RotMat( tempAngles_calc.Pos[2] ,x);

}; // MyModel

// The study: Operations to be performed on the model
AnyBodyStudy MyStudy = {
AnyFolder &Model = .MyModel;
RecruitmentSolver = MinMaxSimplex;
Gravity = {0.0, -9.81, 0.0};
};

}; // Main

Hi David,

I have been looking briefly at your case and you are certainly right that
you should expect the two rotational matrices to become identical.

In other words, I do not think you are doing something wrong.

There is however one small misunderstanding that I would like to correct.
You are right when you write (in the code) that the angles of course can
differ by 2pi. However, this is not the only possibility for different sets
of Euler angles yielding the same orientation. There is also another branch
of solutions. Geometrically, this alternative solution is the case where the
second axis of rotation is oriented directly opposite.

I believe that you are indeed experiencing this case, because your 2 sets of
angles are differing exactly -180 degrees for the 1’st and 3’rd rotation;
this implies that the 2’nd rotation axes are parallel but pointing in
opposite directions.

However, this also implies that the 2’nd rotation from AnyBody is wrong.

In your specific case I found that {-pi+1.5103, pi-0.2263,-pi+ 2.3537} yield
the same rotational matrices as your original angles. I am currently trying
to find out why AnyBody does not provide this solution.

I think this might actually be a bug that have haunted AnyBody for a number
of versions. It is typically not as devastating as it sounds because as soon
as you apply a driver to a rotational measure like this, the measure will
look for the solution among the possible sets that is closes to values of
the driver. Moreover, I think that it only happens in specific cases, i.e.,
certain intervals of angles and certain combinations of rotation axes.

I shall return when I get to the bottom of the matter. Your case definitely
provides a good foundation for doing this - thanks.

Best regards,

Michael

Michael Damsgaard, AnyBody Support

From: anyscript@yahoogroups.com [mailto:anyscript@yahoogroups.com] On Behalf
Of dww805
Sent: Tuesday, November 06, 2007 19:16
To: anyscript@yahoogroups.com
Subject: [AnyScript] Using AnyKinRotational to get the Euler angles

I am getting different results when trying to calculate the Euler angles
when using
AnyKinRotational, type = RotAxesAngles.

Below is some code that I wrote to test this, but what I am trying to do is:
define three angles : {1.5103, 0.2263, 2.3537};
construct an original rotation matrix using those angles
calculate three angles (they may not be the same as the original three) from
the rotation
matrix
calculate a new rotation matrix.

the original rotation matrix should be the same as the new rotation
matrix…this is not
happening for the sequence I have defined:

Thanks for your help. Am I doing something wrong?

-David

Here is the code:

// Todo: Write a small description of your model here
//Load and run set Initial conditions.
//It will fail, but not before it calculates the values of
//tempMatrix, and tempMatric_calc
//
//I think they should be the same…but they are not.
//The tempAngles and tempAngles_calc should be the same and seem to be
//different by a factor of 180 (pi)…when if they are different , I think
they should
//be by a factor of 360 degrees (2*pi)

//Thoughts? Am I doing something wrong here?

Main = {

// The actual body model goes in this folder
AnyFolder MyModel = {

// Global Reference Frame
AnyFixedRefFrame GlobalRef = {

// Todo: Add points for grounding of the model here

}; // Global reference frame

// Todo. Add the model elements such as
// segments, joints, and muscles here.

AnyVector tempAngles = {1.5103, 0.2263, 2.3537};

AnyMatrix tempMatrix = RotMat( tempAngles[0] ,z)*
RotMat( tempAngles[1] ,y)*
RotMat( tempAngles[2] ,x);

AnySeg tempSeg =
{
//r0 = {0, 0, 0};
//rDot0 = {0, 0, 0};
Axes0 = .tempMatrix;
//omega0 = {0, 0, 0};
Mass = 0;
Jii = {0, 0, 0};
//Jij = {0, 0, 0};
//sCoM = {0, 0, 0};
};

AnyKinRotational tempAngles_calc ={

AnyRefFrame &ref1 = .GlobalRef;
AnySeg &ref2 = .tempSeg;
Type=RotAxesAngles;

Axis1 = z;
Axis2 = y;
Axis3 = x;
//finished DW added code
};

AnyMatrix tempMatrix_calc = RotMat( tempAngles_calc.Pos[0] ,z)*
RotMat( tempAngles_calc.Pos[1] ,y)*
RotMat( tempAngles_calc.Pos[2] ,x);

}; // MyModel

// The study: Operations to be performed on the model
AnyBodyStudy MyStudy = {
AnyFolder &Model = .MyModel;
RecruitmentSolver = MinMaxSimplex;
Gravity = {0.0, -9.81, 0.0};
};

}; // Main

[Non-text portions of this message have been removed]

Dear David,

Many month ago, I promised you to find out the reasons for a strange
behavior in AnyKinRotational and get back you.

I did the former based on your model, but not the latter I am afraid.

You even provided me with a nice example of the problem. I really
appreciated this.

Indeed, we fixed a bug in the AnyKinRotational so it now it does as you (and
the rest of us) expected it to. This bug fix is available in Version 3.0.1
of AnyBody including a small description of the issue in the release notes.

My excuse for not getting back to you is not very good - sorry.

I wanted to be able to tell you when the fix was coming out, and at that
time I really believed it was going to be soon.

Then a number of other issues piled up, among others a number of Vista and
installation related issues, and the 3.0.1 bug-fix release was delayed a
lot. and I forgot my promise to you.

I hope you would have reminded me if it was very urgent to you.

Anyway now the new release is available as I guess you saw yesterday (in
message #1858. Please refer to this message if you consider grabbing the new
version.).

`````` AnyVar tempMatrix_diff = max(max(tempMatrix_calc - tempMatrix));
``````

and this quantity becomes practically zero in the new version.

I sincerely apologize for my forgetfulness.

Kind regards,

Michael

Michael Damsgaard, AnyBody Support

From: anyscript@yahoogroups.com [mailto:anyscript@yahoogroups.com] On Behalf
Of dww805
Sent: Tuesday, November 06, 2007 19:16
To: anyscript@yahoogroups.com
Subject: [AnyScript] Using AnyKinRotational to get the Euler angles

I am getting different results when trying to calculate the Euler angles
when using
AnyKinRotational, type = RotAxesAngles.

Below is some code that I wrote to test this, but what I am trying to do is:
define three angles : {1.5103, 0.2263, 2.3537};
construct an original rotation matrix using those angles
calculate three angles (they may not be the same as the original three) from
the rotation
matrix
calculate a new rotation matrix.

the original rotation matrix should be the same as the new rotation
matrix…this is not
happening for the sequence I have defined:

Thanks for your help. Am I doing something wrong?

-David

Here is the code:

// Todo: Write a small description of your model here
//Load and run set Initial conditions.
//It will fail, but not before it calculates the values of
//tempMatrix, and tempMatric_calc
//
//I think they should be the same…but they are not.
//The tempAngles and tempAngles_calc should be the same and seem to be
//different by a factor of 180 (pi)…when if they are different , I think
they should
//be by a factor of 360 degrees (2*pi)

//Thoughts? Am I doing something wrong here?

Main = {

// The actual body model goes in this folder
AnyFolder MyModel = {

// Global Reference Frame
AnyFixedRefFrame GlobalRef = {

// Todo: Add points for grounding of the model here

}; // Global reference frame

// Todo. Add the model elements such as
// segments, joints, and muscles here.

AnyVector tempAngles = {1.5103, 0.2263, 2.3537};

AnyMatrix tempMatrix = RotMat( tempAngles[0] ,z)*
RotMat( tempAngles[1] ,y)*
RotMat( tempAngles[2] ,x);

AnySeg tempSeg =
{
//r0 = {0, 0, 0};
//rDot0 = {0, 0, 0};
Axes0 = .tempMatrix;
//omega0 = {0, 0, 0};
Mass = 0;
Jii = {0, 0, 0};
//Jij = {0, 0, 0};
//sCoM = {0, 0, 0};
};

AnyKinRotational tempAngles_calc ={

AnyRefFrame &ref1 = .GlobalRef;
AnySeg &ref2 = .tempSeg;
Type=RotAxesAngles;

Axis1 = z;
Axis2 = y;
Axis3 = x;
//finished DW added code
};

AnyMatrix tempMatrix_calc = RotMat( tempAngles_calc.Pos[0] ,z)*
RotMat( tempAngles_calc.Pos[1] ,y)*
RotMat( tempAngles_calc.Pos[2] ,x);

}; // MyModel

// The study: Operations to be performed on the model
AnyBodyStudy MyStudy = {
AnyFolder &Model = .MyModel;
RecruitmentSolver = MinMaxSimplex;
Gravity = {0.0, -9.81, 0.0};
};

}; // Main

[Non-text portions of this message have been removed]