mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-23 00:18:46 +00:00
Use explicit precedence
This commit is contained in:
parent
4f123d384e
commit
12ca1b7c18
@ -19,23 +19,23 @@ public static class QuaternionExtensions
|
|||||||
/// <see href="https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/" />
|
/// <see href="https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/" />
|
||||||
public static Vector3d ToEulerAngles(this Quaternion value, bool radians = true)
|
public static Vector3d ToEulerAngles(this Quaternion value, bool radians = true)
|
||||||
{
|
{
|
||||||
double a = 2.0 * value.Y * value.W - 2.0 * value.X * value.Z;
|
double a = (2.0 * value.Y * value.W) - (2.0 * value.X * value.Z);
|
||||||
double b = 1.0 - 2.0 * value.Y * value.Y - 2.0 * value.Z * value.Z;
|
double b = 1.0 - (2.0 * value.Y * value.Y) - (2.0 * value.Z * value.Z);
|
||||||
double y = -Math.Atan2(a, b);
|
double y = -Math.Atan2(a, b);
|
||||||
|
|
||||||
a = 2.0 * value.X * value.Y;
|
a = 2.0 * value.X * value.Y;
|
||||||
b = 2.0 * value.Z * value.W;
|
b = 2.0 * value.Z * value.W;
|
||||||
double z = Math.Asin(a + b);
|
double z = Math.Asin(a + b);
|
||||||
|
|
||||||
a = 2.0 * value.X * value.W - 2.0 * value.Y * value.Z;
|
a = (2.0 * value.X * value.W) - (2.0 * value.Y * value.Z);
|
||||||
b = 1.0 - 2.0 * value.X * value.X - 2.0 * value.Z * value.Z;
|
b = 1.0 - (2.0 * value.X * value.X) - (2.0 * value.Z * value.Z);
|
||||||
double x = Math.Atan2(a, b);
|
double x = Math.Atan2(a, b);
|
||||||
|
|
||||||
if (!radians)
|
if (!radians)
|
||||||
{
|
{
|
||||||
x = (180.0 / Math.PI) * x;
|
x = 180.0 / Math.PI * x;
|
||||||
y = (180.0 / Math.PI) * y;
|
y = 180.0 / Math.PI * y;
|
||||||
z = (180.0 / Math.PI) * z;
|
z = 180.0 / Math.PI * z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Vector3d(x, y, z);
|
return new Vector3d(x, y, z);
|
||||||
@ -52,23 +52,23 @@ public static class QuaternionExtensions
|
|||||||
/// <returns>The Euler representation of <paramref name="value" />.</returns>
|
/// <returns>The Euler representation of <paramref name="value" />.</returns>
|
||||||
public static Vector3d ToEulerAnglesF(this Quaternion value, bool radians = true)
|
public static Vector3d ToEulerAnglesF(this Quaternion value, bool radians = true)
|
||||||
{
|
{
|
||||||
float a = 2.0f * value.Y * value.W - 2.0f * value.X * value.Z;
|
float a = (2.0f * value.Y * value.W) - (2.0f * value.X * value.Z);
|
||||||
float b = 1.0f - 2.0f * value.Y * value.Y - 2.0f * value.Z * value.Z;
|
float b = 1.0f - (2.0f * value.Y * value.Y) - (2.0f * value.Z * value.Z);
|
||||||
float y = -MathF.Atan2(a, b);
|
float y = -MathF.Atan2(a, b);
|
||||||
|
|
||||||
a = 2.0f * value.X * value.Y;
|
a = 2.0f * value.X * value.Y;
|
||||||
b = 2.0f * value.Z * value.W;
|
b = 2.0f * value.Z * value.W;
|
||||||
float z = MathF.Asin(a + b);
|
float z = MathF.Asin(a + b);
|
||||||
|
|
||||||
a = 2.0f * value.X * value.W - 2.0f * value.Y * value.Z;
|
a = (2.0f * value.X * value.W) - (2.0f * value.Y * value.Z);
|
||||||
b = 1.0f - 2.0f * value.X * value.X - 2.0f * value.Z * value.Z;
|
b = 1.0f - (2.0f * value.X * value.X) - (2.0f * value.Z * value.Z);
|
||||||
float x = MathF.Atan2(a, b);
|
float x = MathF.Atan2(a, b);
|
||||||
|
|
||||||
if (!radians)
|
if (!radians)
|
||||||
{
|
{
|
||||||
x = (180.0f / MathF.PI) * x;
|
x = 180.0f / MathF.PI * x;
|
||||||
y = (180.0f / MathF.PI) * y;
|
y = 180.0f / MathF.PI * y;
|
||||||
z = (180.0f / MathF.PI) * z;
|
z = 180.0f / MathF.PI * z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Vector3d(x, y, z);
|
return new Vector3d(x, y, z);
|
||||||
@ -86,9 +86,9 @@ public static class QuaternionExtensions
|
|||||||
{
|
{
|
||||||
angle = 2.0f * MathF.Acos(value.W);
|
angle = 2.0f * MathF.Acos(value.W);
|
||||||
|
|
||||||
float x = value.X / MathF.Sqrt(1.0f - value.W * value.W);
|
float x = value.X / MathF.Sqrt(1.0f - (value.W * value.W));
|
||||||
float y = value.Y / MathF.Sqrt(1.0f - value.W * value.W);
|
float y = value.Y / MathF.Sqrt(1.0f - (value.W * value.W));
|
||||||
float z = value.Z / MathF.Sqrt(1.0f - value.W * value.W);
|
float z = value.Z / MathF.Sqrt(1.0f - (value.W * value.W));
|
||||||
|
|
||||||
axis = new Vector3(x, y, z);
|
axis = new Vector3(x, y, z);
|
||||||
}
|
}
|
||||||
@ -103,9 +103,9 @@ public static class QuaternionExtensions
|
|||||||
{
|
{
|
||||||
angle = 2.0 * Math.Acos(value.W);
|
angle = 2.0 * Math.Acos(value.W);
|
||||||
|
|
||||||
double x = value.X / Math.Sqrt(1.0 - value.W * value.W);
|
double x = value.X / Math.Sqrt(1.0 - (value.W * value.W));
|
||||||
double y = value.Y / Math.Sqrt(1.0 - value.W * value.W);
|
double y = value.Y / Math.Sqrt(1.0 - (value.W * value.W));
|
||||||
double z = value.Z / Math.Sqrt(1.0 - value.W * value.W);
|
double z = value.Z / Math.Sqrt(1.0 - (value.W * value.W));
|
||||||
|
|
||||||
axis = new Vector3d(x, y, z);
|
axis = new Vector3d(x, y, z);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user