reckfellENGINE

Quaternion

A quaternion for representing and interpolating 3D rotation.

On this page
struct QuaternionReckfellSharpInherits ValueType

Use a unit Quaternion for rotation. Quaternion.Identity means no rotation; a zero struct is not identity. Slerp interpolates orientations rather than averaging Euler components.

Inputs must be normalized; weight is a transition fraction. Equivalent orientations may have every quaternion component sign reversed, so raw-component equality is not orientation equality. Rotation stores neither Entity translation nor scale.

Practical guide.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors4

Quaternion4 overloads
# Quaternion · 1/4
C#
public Quaternion(Basis basis);

Constructs a Quaternion defined by the given values. Note: Only normalized quaternions represent rotation; if these values are not normalized, the new Quaternion will not be a valid rotation.

Parameters
NameTypeDefault
basisBasis—
basis

The Basis to construct from.

# Quaternion · 2/4
C#
public Quaternion(Vector3 arcFrom, Vector3 arcTo);

Constructs a Quaternion defined by the given values. Note: Only normalized quaternions represent rotation; if these values are not normalized, the new Quaternion will not be a valid rotation.

Parameters
NameTypeDefault
arcFromVector3—
arcToVector3—
# Quaternion · 3/4
C#
public Quaternion(Vector3 axis, float angle);

Constructs a Quaternion defined by the given values. Note: Only normalized quaternions represent rotation; if these values are not normalized, the new Quaternion will not be a valid rotation.

Parameters
NameTypeDefault
axisVector3—
anglefloat—
axis

The axis to rotate around. Must be normalized.

angle

The angle to rotate, in radians.

# Quaternion · 4/4
C#
public Quaternion(float x, float y, float z, float w);

Constructs a Quaternion defined by the given values. Note: Only normalized quaternions represent rotation; if these values are not normalized, the new Quaternion will not be a valid rotation.

Parameters
NameTypeDefault
xfloat—
yfloat—
zfloat—
wfloat—
x

X component of the quaternion (imaginary i axis part).

y

Y component of the quaternion (imaginary j axis part).

z

Z component of the quaternion (imaginary k axis part).

w

W component of the quaternion (real part).

Properties2

IdentityProperty
# Identity
C#
public static Quaternion Identity { get; }

The identity quaternion, representing no rotation. This has the same rotation as Basis.Identity. If a Vector3 is rotated (multiplied) by this quaternion, it does not change. Note: In C#, this constant is equivalent to creating a [constructor Quaternion] without any arguments. It can be used to make your code clearer, and for consistency with C#.

ItemProperty
# Item
C#
public float this[int index] { get; set; }

Access quaternion components using their index.

Methods36

AngleTofloat
# AngleTo
C#
public float AngleTo(Quaternion to);

Returns the angle between this quaternion and to. This is the magnitude of the angle you would need to rotate by to get from one to the other. Note: The magnitude of the floating-point error for this method is abnormally high, so methods such as is_zero_approx will not work reliably.

Parameters
NameTypeDefault
toQuaternion—
to

The other quaternion.

Returns float

The angle between the quaternions.

Dotfloat
# Dot
C#
public float Dot(Quaternion b);

Returns the dot product between this quaternion and with. This is equivalent to (quat.x * with.x) + (quat.y * with.y) + (quat.z * with.z) + (quat.w * with.w).

Parameters
NameTypeDefault
bQuaternion—
b

The other quaternion.

Returns float

The dot product.

Equals2 overloads
# Equals · 1/2
C#
public bool Equals(Quaternion other);

Returns true if this quaternion and other are equal.

Parameters
NameTypeDefault
otherQuaternion—
other

The other quaternion to compare.

Returns bool

Whether or not the quaternions are exactly equal.

# Equals · 2/2
C#
public override bool Equals(object? obj);

Returns true if this quaternion and obj are equal.

Parameters
NameTypeDefault
objobject—
obj

The other object to compare.

Returns bool

Whether or not the quaternion and the other object are exactly equal.

ExpQuaternion
# Exp
C#
public Quaternion Exp();

Returns the exponential of this quaternion. The rotation axis of the result is the normalized rotation axis of this quaternion, the angle of the result is the length of the vector part of this quaternion.

Returns Quaternion
FromEulerQuaternion
# FromEuler
C#
public static Quaternion FromEuler(Vector3 eulerYXZ);

Constructs a new Quaternion from the given Vector3 of Euler angles, in radians. In Reckfell, Euler angles always use intrinsic order. This method always uses the intrinsic YXZ convention (EULER_ORDER_YXZ).

Parameters
NameTypeDefault
eulerYXZVector3—
eulerYXZ

Euler angles that the quaternion will be rotated by.

Returns Quaternion
GetAnglefloat
# GetAngle
C#
public float GetAngle();

Returns the angle of the rotation represented by this quaternion. Note: The quaternion must be normalized.

Returns float
GetAxisVector3
# GetAxis
C#
public Vector3 GetAxis();

Returns the rotation axis of the rotation represented by this quaternion.

Returns Vector3
GetEulerVector3
# GetEuler
C#
public Vector3 GetEuler(EulerOrder order = EulerOrder.Yxz);

Returns this quaternion's rotation as a Vector3 of Euler angles, in radians. The order of each consecutive rotation can be changed with order (see EulerOrder constants). In Reckfell, Euler angles always use intrinsic order. By default, the intrinsic YXZ convention is used (EULER_ORDER_YXZ): since we are decomposing, local Z (roll) is calculated first, then local X (pitch), and lastly local Y (yaw). When using the opposite method Quaternion.FromEuler to compose a rotation, this order is reversed.

Parameters
NameTypeDefault
orderEulerOrderEulerOrder.Yxz
Returns Vector3

The Euler angle representation of this quaternion.

GetHashCodeint
# GetHashCode
C#
public override int GetHashCode();

Serves as the hash function for Quaternion.

Returns int

A hash code for this quaternion.

InverseQuaternion
# Inverse
C#
public Quaternion Inverse();

Returns the inverse version of this quaternion, inverting the sign of every component except Quaternion.W.

Returns Quaternion

The inverse quaternion.

IsEqualApproxbool
# IsEqualApprox
C#
public bool IsEqualApprox(Quaternion other);

Returns true if this quaternion and to are approximately equal, by calling @GlobalScope.is_equal_approx on each component.

Parameters
NameTypeDefault
otherQuaternion—
other

The other quaternion to compare.

Returns bool

Whether or not the quaternions are approximately equal.

IsFinitebool
# IsFinite
C#
public bool IsFinite();

Returns true if this quaternion is finite, by calling @GlobalScope.is_finite on each component.

Returns bool

Whether this vector is finite or not.

IsNormalizedbool
# IsNormalized
C#
public bool IsNormalized();

Returns true if this quaternion is normalized. See also Quaternion.Normalized.

Returns bool

A bool for whether the quaternion is normalized or not.

Lengthfloat
# Length
C#
public float Length();

Returns this quaternion's length, also called magnitude.

Returns float
LengthSquaredfloat
# LengthSquared
C#
public float LengthSquared();

Returns this quaternion's length, squared. Note: This method is faster than Quaternion.Length, so prefer it if you only need to compare quaternion lengths.

Returns float
LogQuaternion
# Log
C#
public Quaternion Log();

Returns the logarithm of this quaternion. Multiplies this quaternion's rotation axis by its rotation angle, and stores the result in the returned quaternion's vector part (Quaternion.X, Quaternion.Y, and Quaternion.Z). The returned quaternion's real part (Quaternion.W) is always 0.0.

Returns Quaternion
NormalizedQuaternion
# Normalized
C#
public Quaternion Normalized();

Returns a copy of this quaternion, normalized so that its length is 1.0. See also Quaternion.IsNormalized.

Returns Quaternion

The normalized quaternion.

SlerpQuaternion
# Slerp
C#
public Quaternion Slerp(Quaternion to, float weight);

Spherically interpolates between unit orientation quaternions. Weight is a transition fraction, not angular speed or seconds.

Parameters
NameTypeDefault
toQuaternion—
weightfloat—
to

The destination quaternion for interpolation. Must be normalized.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Quaternion

The resulting quaternion of the interpolation.

SlerpniQuaternion
# Slerpni
C#
public Quaternion Slerpni(Quaternion to, float weight);

Performs a spherical-linear interpolation with the to quaternion, given a weight and returns the result. Unlike Quaternion.Slerp, this method does not check if the rotation path is smaller than 90 degrees. Both this quaternion and to must be normalized.

Parameters
NameTypeDefault
toQuaternion—
weightfloat—
to

The destination quaternion for interpolation. Must be normalized.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Quaternion

The resulting quaternion of the interpolation.

SphericalCubicInterpolateQuaternion
# SphericalCubicInterpolate
C#
public Quaternion SphericalCubicInterpolate(Quaternion b, Quaternion preA, Quaternion postB, float weight);

Performs a spherical cubic interpolation between quaternions pre_a, this quaternion, b, and post_b, by the given amount weight.

Parameters
NameTypeDefault
bQuaternion—
preAQuaternion—
postBQuaternion—
weightfloat—
b

The destination quaternion.

preA

A quaternion before this quaternion.

postB

A quaternion after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Quaternion

The interpolated quaternion.

SphericalCubicInterpolateInTimeQuaternion
# SphericalCubicInterpolateInTime
C#
public Quaternion SphericalCubicInterpolateInTime(Quaternion b, Quaternion preA, Quaternion postB, float weight, float bT, float preAT, float postBT);

Performs a spherical cubic interpolation between quaternions pre_a, this quaternion, b, and post_b, by the given amount weight. It can perform smoother interpolation than Quaternion.SphericalCubicInterpolate by the time values.

Parameters
NameTypeDefault
bQuaternion—
preAQuaternion—
postBQuaternion—
weightfloat—
bTfloat—
preATfloat—
postBTfloat—
b

The destination quaternion.

preA

A quaternion before this quaternion.

postB

A quaternion after b.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Quaternion

The interpolated quaternion.

ToString2 overloads
# ToString · 1/2
C#
public override string ToString();

Converts this Quaternion to a string.

Returns string

A string representation of this quaternion.

# ToString · 2/2
C#
public string ToString(string? format);

Converts this Quaternion to a string with the given format.

Parameters
NameTypeDefault
formatstring—
Returns string

A string representation of this quaternion.

op_AdditionQuaternion
# op_Addition
C#
public static Quaternion operator +(Quaternion left, Quaternion right);

Adds each component of the left Quaternion to the right Quaternion. This operation is not meaningful on its own, but it can be used as a part of a larger expression, such as approximating an intermediate rotation between two nearby rotations.

Parameters
NameTypeDefault
leftQuaternion—
rightQuaternion—
left

The left quaternion to add.

right

The right quaternion to add.

Returns Quaternion

The added quaternion.

op_DivisionQuaternion
# op_Division
C#
public static Quaternion operator /(Quaternion left, float right);

Divides each component of the Quaternion by the given System.Single. This operation is not meaningful on its own, but it can be used as a part of a larger expression.

Parameters
NameTypeDefault
leftQuaternion—
rightfloat—
left

The quaternion to divide.

right

The value to divide by.

Returns Quaternion

The divided quaternion.

op_Equalitybool
# op_Equality
C#
public static bool operator ==(Quaternion left, Quaternion right);

Returns true if the quaternions are exactly equal. Note: Due to floating-point precision errors, consider using Quaternion.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftQuaternion—
rightQuaternion—
left

The left quaternion.

right

The right quaternion.

Returns bool

Whether or not the quaternions are exactly equal.

op_Inequalitybool
# op_Inequality
C#
public static bool operator !=(Quaternion left, Quaternion right);

Returns true if the quaternions are not equal. Note: Due to floating-point precision errors, consider using Quaternion.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftQuaternion—
rightQuaternion—
left

The left quaternion.

right

The right quaternion.

Returns bool

Whether or not the quaternions are not equal.

op_Multiply5 overloads
# op_Multiply · 1/5
C#
public static Quaternion operator *(Quaternion left, Quaternion right);

Composes these two quaternions by multiplying them together. This has the effect of rotating the second quaternion (the child) by the first quaternion (the parent).

Parameters
NameTypeDefault
leftQuaternion—
rightQuaternion—
left

The parent quaternion.

right

The child quaternion.

Returns Quaternion

The composed quaternion.

# op_Multiply · 2/5
C#
public static Vector3 operator *(Quaternion quaternion, Vector3 vector);

Returns a Vector3 rotated (multiplied) by the quaternion.

Parameters
NameTypeDefault
quaternionQuaternion—
vectorVector3—
quaternion

The quaternion to rotate by.

vector

A Vector3 to transform.

Returns Vector3

The rotated Vector3.

# op_Multiply · 3/5
C#
public static Quaternion operator *(Quaternion left, float right);

Multiplies each component of the Quaternion by the given System.Single. This operation is not meaningful on its own, but it can be used as a part of a larger expression.

Parameters
NameTypeDefault
leftQuaternion—
rightfloat—
left

The quaternion to multiply.

right

The value to multiply by.

Returns Quaternion

The multiplied quaternion.

# op_Multiply · 4/5
C#
public static Vector3 operator *(Vector3 vector, Quaternion quaternion);

Returns a Vector3 rotated (multiplied) by the inverse quaternion. vector * quaternion is equivalent to quaternion.Inverse() * vector. See Quaternion.Inverse.

Parameters
NameTypeDefault
vectorVector3—
quaternionQuaternion—
vector

A Vector3 to inversely rotate.

quaternion

The quaternion to rotate by.

Returns Vector3

The inversely rotated Vector3.

# op_Multiply · 5/5
C#
public static Quaternion operator *(float left, Quaternion right);

Multiplies each component of the Quaternion by the given System.Single. This operation is not meaningful on its own, but it can be used as a part of a larger expression.

Parameters
NameTypeDefault
leftfloat—
rightQuaternion—
left

The value to multiply by.

right

The quaternion to multiply.

Returns Quaternion

The multiplied quaternion.

op_SubtractionQuaternion
# op_Subtraction
C#
public static Quaternion operator -(Quaternion left, Quaternion right);

Subtracts each component of the left Quaternion by the right Quaternion. This operation is not meaningful on its own, but it can be used as a part of a larger expression.

Parameters
NameTypeDefault
leftQuaternion—
rightQuaternion—
left

The left quaternion to subtract.

right

The right quaternion to subtract.

Returns Quaternion

The subtracted quaternion.

op_UnaryNegationQuaternion
# op_UnaryNegation
C#
public static Quaternion operator -(Quaternion quat);

Returns the negative value of the Quaternion. This is the same as writing new Quaternion(-q.X, -q.Y, -q.Z, -q.W). This operation results in a quaternion that represents the same rotation.

Parameters
NameTypeDefault
quatQuaternion—
quat

The quaternion to negate.

Returns Quaternion

The negated quaternion.

op_UnaryPlusQuaternion
# op_UnaryPlus
C#
public static Quaternion operator +(Quaternion quat);

Returns the same value as if the + was not there. Unary + does nothing, but sometimes it can make your code more readable.

Parameters
NameTypeDefault
quatQuaternion—
quat

The quaternion to do nothing to.

Returns Quaternion

The original quaternion.

Fields and constants4

WField
# W
C#
public float W;

W component of the quaternion. This is the "real" part. Note: Quaternion components should usually not be manipulated directly.

XField
# X
C#
public float X;

X component of the quaternion. This is the value along the "imaginary" i axis. Note: Quaternion components should usually not be manipulated directly.

YField
# Y
C#
public float Y;

Y component of the quaternion. This is the value along the "imaginary" j axis. Note: Quaternion components should usually not be manipulated directly.

ZField
# Z
C#
public float Z;

Z component of the quaternion. This is the value along the "imaginary" k axis. Note: Quaternion components should usually not be manipulated directly.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.