Quaternion
La référence est en anglais : elle est générée à partir des commentaires du code, écrits en anglais.
public struct Quaternion : IEquatable<Quaternion>, IFormattableNamespace NodeWorld.Flux.
A rotation (unit quaternion, Hamilton product: lhs * rhs rotates by rhs, then by lhs). Euler angles in degrees, applied around z, then x, then y (the convention of Unity).
Constants
kEpsilon
public const float kEpsilon = 0.000001fThe tolerance of ==: two rotations are equal when the dot product of their quaternions is above 1 - kEpsilon.
Fields
x
public float xx of the vector part (not an angle).
y
public float yy of the vector part (not an angle).
z
public float zz of the vector part (not an angle).
w
public float wThe scalar part (not an angle).
Constructors
Quaternion
public Quaternion(float x, float y, float z, float w)A quaternion of these four components.
Properties
identity
public static Quaternion identity { get; }No rotation.
this[]
public float this[int index] { get; set; }x, y, z, w by index 0 to 3.
eulerAngles
public Vector3 eulerAngles { get; set; }The Euler angles in degrees, each in [0, 360).
normalized
public Quaternion normalized { get; }This quaternion at length 1.
Methods
Set
public void Set(float newX, float newY, float newZ, float newW)Sets the four components.
Dot
public static float Dot(Quaternion a, Quaternion b)Dot product of two quaternions.
Angle
public static float Angle(Quaternion a, Quaternion b)Angle in degrees between two rotations.
Euler
public static Quaternion Euler(float x, float y, float z)The rotation of z degrees around the z axis, then x degrees around the x axis, then y degrees around the y axis, as Unity's.
public static Quaternion Euler(Vector3 euler)Euler(euler.x, euler.y, euler.z).
AngleAxis
public static Quaternion AngleAxis(float angle, Vector3 axis)The rotation of angle degrees around axis; identity for a zero axis.
ToAngleAxis
public void ToAngleAxis(out float angle, out Vector3 axis)The angle in degrees and the axis of this rotation (the x axis when there is no rotation).
Inverse
public static Quaternion Inverse(Quaternion rotation)The opposite rotation.
Normalize
public static Quaternion Normalize(Quaternion q)q at length 1 (identity for a zero quaternion).
public void Normalize()Brings this quaternion to length 1.
Lerp
public static Quaternion Lerp(Quaternion a, Quaternion b, float t)From a (t = 0) to b (t = 1), the short way, normalized: quicker than Slerp, less even. t is kept between 0 and 1.
LerpUnclamped
public static Quaternion LerpUnclamped(Quaternion a, Quaternion b, float t)From a (t = 0) to b (t = 1), the short way, normalized; t is not limited.
Slerp
public static Quaternion Slerp(Quaternion a, Quaternion b, float t)From a (t = 0) to b (t = 1) at an even angular speed, the short way. t is kept between 0 and 1.
SlerpUnclamped
public static Quaternion SlerpUnclamped(Quaternion a, Quaternion b, float t)From a (t = 0) to b (t = 1) at an even angular speed, the short way; t is not limited.
RotateTowards
public static Quaternion RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta)from turned towards to by maxDegreesDelta degrees at most.
LookRotation
public static Quaternion LookRotation(Vector3 forward, Vector3 upwards)The rotation whose forward (z) is "forward" and whose up is as close as possible to "upwards".
public static Quaternion LookRotation(Vector3 forward)The rotation whose forward (z) is forward and whose up is as close as possible to the world's up.
FromToRotation
public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection)The rotation that turns fromDirection onto toDirection.
Equals
public bool Equals(Quaternion other)The four components are exactly equal.
public override bool Equals(object other)other is a quaternion with exactly the same components.
GetHashCode
public override int GetHashCode()A hash of the components.
ToString
public override string ToString()"(x, y, z, w)" with 5 decimals.
public string ToString(string format)The same text with the numbers in format.
public string ToString(string format, IFormatProvider formatProvider)The same text with the numbers in format (F5 when empty) and formatProvider (the invariant culture when null).
Operators
operator *
public static Quaternion operator *(Quaternion lhs, Quaternion rhs)The two rotations in sequence, as Unity's: lhs, then rhs in the frame lhs made.
public static Vector3 operator *(Quaternion rotation, Vector3 point)Rotates the point: v + 2w (u x v) + 2 u x (u x v), with u the vector part.
operator ==
public static bool operator ==(Quaternion lhs, Quaternion rhs)Same rotation (q and -q included) up to 1e-6.
operator !=
public static bool operator !=(Quaternion lhs, Quaternion rhs)The rotations differ (see ==).
