C#: Add Exp and Log to Quaternion

This commit is contained in:
Raul Santos 2022-08-24 13:00:43 +02:00
parent b526a0d824
commit 8ad0ef75b8
No known key found for this signature in database
GPG key ID: B532473AE3A803E4

View file

@ -158,6 +158,18 @@ namespace Godot
return (x * b.x) + (y * b.y) + (z * b.z) + (w * b.w);
}
public Quaternion Exp()
{
Vector3 v = new Vector3(x, y, z);
real_t theta = v.Length();
v = v.Normalized();
if (theta < Mathf.Epsilon || !v.IsNormalized())
{
return new Quaternion(0, 0, 0, 1);
}
return new Quaternion(v, theta);
}
public real_t GetAngle()
{
return 2 * Mathf.Acos(w);
@ -217,6 +229,12 @@ namespace Godot
return Mathf.Abs(LengthSquared - 1) <= Mathf.Epsilon;
}
public Quaternion Log()
{
Vector3 v = GetAxis() * GetAngle();
return new Quaternion(v.x, v.y, v.z, 0);
}
/// <summary>
/// Returns a copy of the quaternion, normalized to unit length.
/// </summary>