# Quaternion and Euler angle confusion

I’m attempting to set the rotation of my RootNode children to a certain value that aligns it correctly to other files (coordinate system in Unity 3D).

I’m setting EulerAngles directly:
`node.Transform.EulerAngles = new Vector3( -90, 0, 180 );`

When I read the property immediately afterwards I get the following back: (x: 180 y: 0 z: 180)

This is clearly incorrect.

I’ve written more unit tests to try and figure out what is going on, and It’s just adding to confusion.

``````    public const double RadToDegree = 180 / Math.PI;
public const double DegreeToRad = Math.PI / 180;

[Test]
public void SimpleQuaternionTest()
{
var q1 = Quaternion.FromEulerAngle( 0, 0, 180 * DegreeToRad);

Assert.AreEqual( q1, q2 );
}
``````

The above fails. A 180 degree roll should equal a 180 degree yaw and 180 pitch.

The following fail whenever I use 180 degrees for an axis.

``````    [ Test ]
[ TestCase( 0, 0, 0 ) ]
[ TestCase( 20, 45, 0 ) ]
[ TestCase( 45, 0, 0 ) ]
[ TestCase( 0, 60, 0 ) ]
[ TestCase( 0, 90, 0 ) ]
[ TestCase( 0, 120, 0 ) ]
[ TestCase( 0, 179, 0 ) ]
[ TestCase( 0, 180, 0 ) ]
[ TestCase( 0, 0, 180 ) ]
public void QuaternionEulerTests( double pitch, double yaw, double roll )
{
// https://reference.aspose.com/net/3d/aspose.threed.utilities.quaternion/fromeulerangle/methods/1

// Parameters
//     pitch
//      Type: System.Double
//     yaw
//      Type: System.Double
//     roll
//      Type: System.Double

// Quaternion.EulerAngles Method
// Converts quaternion to rotation represented by euler angles All components are in radian
var quaternionToEuler = quaternionFromEuler.EulerAngles();

// My extension method
var quaternionEulerDegrees = quaternionToEuler.ToDegrees();

Assert.AreEqual( pitch * ThreeDExtensions.DegreeToRad, quaternionFromEuler.EulerAngles().x, TestTolerance );
Assert.AreEqual( yaw * ThreeDExtensions.DegreeToRad, quaternionFromEuler.EulerAngles().y, TestTolerance );
Assert.AreEqual( roll * ThreeDExtensions.DegreeToRad, quaternionFromEuler.EulerAngles().z, TestTolerance );
}
``````
``````public static class ThreeDExtensions
{
public static Vector3 ToDegrees( this Vector3 eulerRadians )
{
return new Vector3( 180 / Math.PI * eulerRadians.x, 180 / Math.PI * eulerRadians.y, 180 / Math.PI * eulerRadians.z );
}

public static Vector3 ToRadians( this Vector3 eulerDegrees )
{
return new Vector3( Math.PI / 180 * eulerDegrees.x, Math.PI / 180 * eulerDegrees.y, Math.PI / 180 * eulerDegrees.z );
}

public const double RadToDegree = 180 / Math.PI;
public const double DegreeToRad = Math.PI / 180;
}``````

Kindly send us a sample 3D model and the complete code because there are unknown objects in the code. We will investigate your scenario in our environment and share our findings with you.

Imran,

I’ve uploaded the vs2017 solution with unit tests that I believe indicate an error in Quaternion and Euler calculations. It seems the calculations only fail when one axis has a 180 degree rotation.

No models are necessary as the error is in the quaternion euler angles.

AsposeThreeDTests.zip (5.5 KB)

Please see the “RotateNodeTwoAxis” unit test for the clearest indication of the error. A euler rotation of -90, 0, 180 ends up being 180, 0, 180.

image.png (7.5 KB)

See attached image. EulerAngles becomes 180, 0, 180 immediately after setting it to -90, 0, 180.

We managed to replicate the said behavior in our environment. An investigation has been logged under the ticket ID THREEDNET-392 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

1 Like

The issues you have found earlier (filed as THREEDNET-392) have been fixed in Aspose.3D for .NET 18.5 API. This message was posted using BugNotificationTool from Downloads module by imran.rafique