docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct Quaternion<C>

    A quaternion whose components are expressed in coordinate space C.

    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.SimulationPro.Foundation
    Assembly: Unity.SimulationPro.Foundation.dll
    Syntax
    [Serializable]
    public struct Quaternion<C> where C : ICoordinateSpace, new()
    Type Parameters
    Name Description
    C

    The coordinate space type. Must implement ICoordinateSpace and have a public parameterless constructor.

    Remarks

    Construct from a Unity Quaternion (RUF) using new Quaternion<C>(unityQuat) — the conversion to frame C is applied automatically. Retrieve the Unity equivalent via toUnity. Converts implicitly to QuaternionMsg.

    Constructors

    Quaternion(float, float, float, float)

    Initializes a new Quaternion<C> from raw components already in space C. No coordinate conversion is applied.

    Declaration
    public Quaternion(float x, float y, float z, float w)
    Parameters
    Type Name Description
    float x

    X-axis component.

    float y

    Y-axis component.

    float z

    Z-axis component.

    float w

    W (scalar) component of the quaternion.

    Quaternion(Quaternion)

    Initializes a new Quaternion<C> by converting a Unity (RUF) quaternion into coordinate space C.

    Declaration
    public Quaternion(Quaternion ruf)
    Parameters
    Type Name Description
    Quaternion ruf

    The quaternion in Unity (RUF) space.

    Properties

    toUnity

    Gets the equivalent Unity (RUF) Quaternion by converting from space C.

    Declaration
    public Quaternion toUnity { get; }
    Property Value
    Type Description
    Quaternion

    w

    Gets or sets the W component in coordinate space C.

    Declaration
    public float w { get; set; }
    Property Value
    Type Description
    float

    x

    Gets or sets the X component in coordinate space C.

    Declaration
    public float x { get; set; }
    Property Value
    Type Description
    float

    y

    Gets or sets the Y component in coordinate space C.

    Declaration
    public float y { get; set; }
    Property Value
    Type Description
    float

    z

    Gets or sets the Z component in coordinate space C.

    Declaration
    public float z { get; set; }
    Property Value
    Type Description
    float

    Methods

    Angle(Quaternion<C>, Quaternion<C>)

    Returns the angle in degrees between two quaternions in space C.

    Declaration
    public static float Angle(Quaternion<C> a, Quaternion<C> b)
    Parameters
    Type Name Description
    Quaternion<C> a

    First operand.

    Quaternion<C> b

    Second operand.

    Returns
    Type Description
    float

    The angle in degrees between a and b.

    AngleAxis(float, Vector3<C>)

    Creates a rotation that rotates angle degrees around axis in space C.

    Declaration
    public static Quaternion<C> AngleAxis(float angle, Vector3<C> axis)
    Parameters
    Type Name Description
    float angle

    Rotation angle in degrees.

    Vector3<C> axis

    The axis to rotate around.

    Returns
    Type Description
    Quaternion<C>

    A quaternion representing a rotation of angle degrees around axis.

    Dot(Quaternion<C>, Quaternion<C>)

    Returns the dot product of two quaternions in space C.

    Declaration
    public static float Dot(Quaternion<C> a, Quaternion<C> b)
    Parameters
    Type Name Description
    Quaternion<C> a

    First operand.

    Quaternion<C> b

    Second operand.

    Returns
    Type Description
    float

    The scalar dot product of a and b.

    Equals(object)

    Declaration
    public override bool Equals(object other)
    Parameters
    Type Name Description
    object other
    Returns
    Type Description
    bool
    Overrides
    ValueType.Equals(object)

    Equals(Quaternion<C>)

    Declaration
    public bool Equals(Quaternion<C> other)
    Parameters
    Type Name Description
    Quaternion<C> other
    Returns
    Type Description
    bool

    FromToRotation(Vector3<C>, Vector3<C>)

    Creates a rotation that rotates from fromDirection to toDirection in space C.

    Declaration
    public static Quaternion<C> FromToRotation(Vector3<C> fromDirection, Vector3<C> toDirection)
    Parameters
    Type Name Description
    Vector3<C> fromDirection

    Direction vector in the source coordinate space.

    Vector3<C> toDirection

    Direction vector in the target coordinate space.

    Returns
    Type Description
    Quaternion<C>

    A rotation that transforms fromDirection into toDirection.

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    ValueType.GetHashCode()

    Inverse(Quaternion<C>)

    Returns the inverse of the given rotation.

    Declaration
    public static Quaternion<C> Inverse(Quaternion<C> rotation)
    Parameters
    Type Name Description
    Quaternion<C> rotation

    The quaternion to invert.

    Returns
    Type Description
    Quaternion<C>

    The inverse quaternion, which reverses the rotation of rotation.

    Lerp(Quaternion<C>, Quaternion<C>, float)

    Linearly interpolates between two quaternions with t clamped to [0,1].

    Declaration
    public static Quaternion<C> Lerp(Quaternion<C> a, Quaternion<C> b, float t)
    Parameters
    Type Name Description
    Quaternion<C> a

    First operand.

    Quaternion<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Quaternion<C>

    The interpolated quaternion between a and b.

    LerpUnclamped(Quaternion<C>, Quaternion<C>, float)

    Linearly interpolates between two quaternions without clamping t.

    Declaration
    public static Quaternion<C> LerpUnclamped(Quaternion<C> a, Quaternion<C> b, float t)
    Parameters
    Type Name Description
    Quaternion<C> a

    First operand.

    Quaternion<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Quaternion<C>

    The interpolated quaternion between a and b.

    LookRotation(Vector3<C>)

    Creates a look rotation aligned with forward in space C.

    Declaration
    public static Quaternion<C> LookRotation(Vector3<C> forward)
    Parameters
    Type Name Description
    Vector3<C> forward

    Forward direction vector.

    Returns
    Type Description
    Quaternion<C>

    A rotation looking along forward with up defaulting to the world up direction.

    Normalize()

    Normalizes this quaternion in-place to unit length.

    Declaration
    public void Normalize()

    Normalize(Quaternion<C>)

    Returns the normalized form of the given quaternion.

    Declaration
    public static Quaternion<C> Normalize(Quaternion<C> q)
    Parameters
    Type Name Description
    Quaternion<C> q

    The quaternion to normalize.

    Returns
    Type Description
    Quaternion<C>

    A unit-length quaternion with the same orientation as q.

    RotateTowards(Quaternion<C>, Quaternion<C>, float)

    Rotates from towards to by at most maxDegreesDelta.

    Declaration
    public static Quaternion<C> RotateTowards(Quaternion<C> from, Quaternion<C> to, float maxDegreesDelta)
    Parameters
    Type Name Description
    Quaternion<C> from

    The starting rotation.

    Quaternion<C> to

    The target rotation.

    float maxDegreesDelta

    Maximum rotation step in degrees.

    Returns
    Type Description
    Quaternion<C>

    A rotation moved from from towards to.

    Set(float, float, float, float)

    Sets the X, Y, Z, and W components of this quaternion.

    Declaration
    public void Set(float newX, float newY, float newZ, float newW)
    Parameters
    Type Name Description
    float newX

    New X component value.

    float newY

    New Y component value.

    float newZ

    New Z component value.

    float newW

    New W component value.

    SetFromToRotation(Vector3<C>, Vector3<C>)

    Sets this quaternion to the rotation from fromDirection to toDirection.

    Declaration
    public void SetFromToRotation(Vector3<C> fromDirection, Vector3<C> toDirection)
    Parameters
    Type Name Description
    Vector3<C> fromDirection

    Direction vector in the source coordinate space.

    Vector3<C> toDirection

    Direction vector in the target coordinate space.

    SetLookRotation(Vector3<C>)

    Sets this quaternion to a look rotation aligned with view.

    Declaration
    public void SetLookRotation(Vector3<C> view)
    Parameters
    Type Name Description
    Vector3<C> view

    The forward direction to look along.

    Slerp(Quaternion<C>, Quaternion<C>, float)

    Spherically interpolates between two quaternions with t clamped to [0,1].

    Declaration
    public static Quaternion<C> Slerp(Quaternion<C> a, Quaternion<C> b, float t)
    Parameters
    Type Name Description
    Quaternion<C> a

    First operand.

    Quaternion<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Quaternion<C>

    The spherically interpolated quaternion between a and b.

    SlerpUnclamped(Quaternion<C>, Quaternion<C>, float)

    Spherically interpolates between two quaternions without clamping t.

    Declaration
    public static Quaternion<C> SlerpUnclamped(Quaternion<C> a, Quaternion<C> b, float t)
    Parameters
    Type Name Description
    Quaternion<C> a

    First operand.

    Quaternion<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Quaternion<C>

    The spherically interpolated quaternion between a and b.

    ToAngleAxis(out float, out Vector3<C>)

    Converts this quaternion to an angle-axis representation in space C.

    Declaration
    public void ToAngleAxis(out float angle, out Vector3<C> axis)
    Parameters
    Type Name Description
    float angle

    Receives the rotation angle in degrees.

    Vector3<C> axis

    Receives the rotation axis in space C.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    ValueType.ToString()

    ToString(string)

    Returns a formatted string for this quaternion using the specified numeric format.

    Declaration
    public string ToString(string format)
    Parameters
    Type Name Description
    string format

    A standard or custom numeric format string (e.g., "F2").

    Returns
    Type Description
    string

    A string representation of the quaternion components formatted according to format.

    ToString(string, IFormatProvider)

    Declaration
    public string ToString(string format, IFormatProvider formatProvider)
    Parameters
    Type Name Description
    string format
    IFormatProvider formatProvider
    Returns
    Type Description
    string

    To<C2>()

    Converts this quaternion to another coordinate space C2 by round-tripping through Unity (RUF).

    Declaration
    public Quaternion<C2> To<C2>() where C2 : ICoordinateSpace, new()
    Returns
    Type Description
    Quaternion<C2>

    The equivalent quaternion in space C2.

    Type Parameters
    Name Description
    C2

    The target coordinate space.

    Operators

    explicit operator Quaternion(Quaternion<C>)

    Explicitly converts a Quaternion<C> to a Unity (RUF) Quaternion.

    Declaration
    public static explicit operator Quaternion(Quaternion<C> rquat)
    Parameters
    Type Name Description
    Quaternion<C> rquat

    The typed quaternion to convert.

    Returns
    Type Description
    Quaternion

    The equivalent Unity (RUF) quaternion.

    explicit operator Quaternion<C>(Quaternion)

    Explicitly converts a Unity (RUF) Quaternion to a Quaternion<C>.

    Declaration
    public static explicit operator Quaternion<C>(Quaternion quat)
    Parameters
    Type Name Description
    Quaternion quat

    The Unity quaternion to convert.

    Returns
    Type Description
    Quaternion<C>

    The quaternion in coordinate space C.

    implicit operator QuaternionMsg(Quaternion<C>)

    Implicitly converts a Quaternion<C> to a QuaternionMsg using its raw components.

    Declaration
    public static implicit operator QuaternionMsg(Quaternion<C> quat)
    Parameters
    Type Name Description
    Quaternion<C> quat

    The typed quaternion to convert.

    Returns
    Type Description
    QuaternionMsg

    A QuaternionMsg with the same X, Y, Z, and W values.

    operator *(Quaternion<C>, Quaternion<C>)

    Combines two rotations in space C.

    Declaration
    public static Quaternion<C> operator *(Quaternion<C> lhs, Quaternion<C> rhs)
    Parameters
    Type Name Description
    Quaternion<C> lhs

    The first rotation to apply.

    Quaternion<C> rhs

    The second rotation to apply.

    Returns
    Type Description
    Quaternion<C>

    A quaternion representing the combined rotation of lhs followed by rhs.

    operator *(Quaternion<C>, Vector3<C>)

    Rotates a Vector3<C> by this quaternion.

    Declaration
    public static Vector3<C> operator *(Quaternion<C> rotation, Vector3<C> point)
    Parameters
    Type Name Description
    Quaternion<C> rotation

    The rotation to apply.

    Vector3<C> point

    The vector to rotate.

    Returns
    Type Description
    Vector3<C>

    The rotated vector.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)