Quaternion

 

 

Quaternion Struct

 

Represents a quaternion orientation.

 

Syntax

public struct Quaternion

 

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Members

See Also: Inherited members from ValueType.

Public Constructors

  Creates a new quaternion with the supplied values.
  Creates a new quaternion with the supplied values.

Public Fields

static readonly
Identity Quaternion . The identity quaternion.

Public Properties

default property
Item (int) float . Allows getting coordinates by index.
  W float . The W coordinate of the quaternion.
  X float . The X coordinate of the quaternion.
  Y float . The Y coordinate of the quaternion.
  Z float . The Z coordinate of the quaternion.

Public Methods

  Dot (ref Quaternion) : float
Performs a scalar or dot product.
static
FromAngleAxis (float, ref Vector) : Quaternion
Generates the corresponding quaternion.
static
FromEulerAngles (ref Vector) : Quaternion
Generates the corresponding quaternion.
static
FromLook (Vector, Vector) : Quaternion
Creates a new rotation with the specified direction and up vectors.
static
FromLookOrthoNormal (ref Vector, ref Vector, ref Vector) : Quaternion
Creates a new rotation with the specified direction and up vectors.
  GetEulerAngles () : Vector
Converts this rotation to a vector of euler angles
  Inverse () : Quaternion
Gets the Inverse of the quaternion.
  Length () : float
Calculates the length of this quaternion.
  LengthSquared () : float
Calculates the length squared of this quaternion.
  Normalized () : Quaternion
Returns a quaternion with the same orientation and unit length.
static
Parse (string) : Quaternion
Parse a Quaternion from a string.
static
ShortestRotation (ref Vector, ref Vector) : Quaternion
Generates the shortest rotation quaternion to rotate from one vector to another.
  ToAngleAxis (out float, out Vector)
Gets the angle-axis representation
override
ToString () : string
Generates a string representation of the quaternion.
  ToString (string) : string
Generates a string representation of the quaternion.
static
TryParse (string, out Quaternion) : bool
Try to parse a Quaternion from a string.

Public Operators

static
Multiply (ref Quaternion, ref Quaternion) Multiplies two quaternions.
static
UnaryNegation Negates a quaternion
static
Conversion to Sansar.Quaternion (Implicit) Converts a Mono.Simd.Vector4f to a quaternion.
static
Conversion to Mono.Simd.Vector4f (Implicit) Converts a quaternion to a Mono.Simd.Vector4f.

 

Member Details

Quaternion Constructor

Creates a new quaternion with the supplied values.

Syntax

public Quaternion ([System.Runtime.CompilerServices.IsReadOnly] ref Mono.Simd.Vector4f v)

Parameters

v
Initializes the quaternion from a Mono.Simd.Vector4f.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Quaternion Constructor

Creates a new quaternion with the supplied values.

Syntax

public Quaternion (float x, float y, float z, float w)

Parameters

x
The x coordinate.
y
The y coordinate.
z
The z coordinate.
w
The w coordinate.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Dot Method

Performs a scalar or dot product.

Syntax

public float Dot ([System.Runtime.CompilerServices.IsReadOnly] ref Quaternion b)

Parameters

b
The second quaternion.

Returns

Returns X*b.X+Y*b.Y+Z*b.Z+W*b.W

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

FromAngleAxis Method

Generates the corresponding quaternion.

Syntax

public static Quaternion FromAngleAxis (float angle, [System.Runtime.CompilerServices.IsReadOnly] ref Vector axis)

Parameters

angle
Angle of rotation in radians
axis
A normalized axis of rotation

Returns

The corresponding quaternion.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

FromEulerAngles Method

Generates the corresponding quaternion.

Syntax

public static Quaternion FromEulerAngles ([System.Runtime.CompilerServices.IsReadOnly] ref Vector a)

Parameters

a
A vector of angles in radians.

Returns

The corresponding quaternion.

Remarks

Rotates first around X (local/global coincide), then around new local Y, and finally around new local Z.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

FromLook Method

Creates a new rotation with the specified direction and up vectors.

Syntax

public static Quaternion FromLook (Vector facing, Vector up)

Parameters

facing
The direction to look.
up
The up direction.

Returns

A new quaternion representing this rotation.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

FromLookOrthoNormal Method

Creates a new rotation with the specified direction and up vectors.

Syntax

public static Quaternion FromLookOrthoNormal ([System.Runtime.CompilerServices.IsReadOnly] ref Vector facing, [System.Runtime.CompilerServices.IsReadOnly] ref Vector up, [System.Runtime.CompilerServices.IsReadOnly] ref Vector left)

Parameters

facing
The direction to look.
up
The up direction.
left
The left direction.

Returns

A new quaternion representing this rotation.

Remarks

The 3 given vectors must be orthonormal. See Vector.Orthonormalize(Vector@, Vector@)

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

GetEulerAngles Method

Converts this rotation to a vector of euler angles

Syntax

public Vector GetEulerAngles ()

Returns

A vector of angles in radians corresponding to this quaternion.

Remarks

Returns angles which can be passed to Quaternion.FromEulerAngles(Vector@) to create this quaternion.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Identity Field

The identity quaternion.

Syntax

public static readonly Quaternion Identity

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Inverse Method

Gets the Inverse of the quaternion.

Syntax

public Quaternion Inverse ()

Returns

A quaternion inverse, such that q * q.Inverse() == q.Inverse() * q == Quaternion.Identity

Remarks

Results are undefined if the length of the quaternion is close to 0.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Item Property

Allows getting coordinates by index.

Syntax

This is the default property for this class.

public float this [int index] { get; set; }

Parameters

index
0=>X, 1=>Y, 2=>Z, 3=>W

Value

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Length Method

Calculates the length of this quaternion.

Syntax

public float Length ()

Returns

The length of the quaternion.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

LengthSquared Method

Calculates the length squared of this quaternion.

Syntax

public float LengthSquared ()

Returns

The magnitude of the vector.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Normalized Method

Returns a quaternion with the same orientation and unit length.

Syntax

public Quaternion Normalized ()

Returns

A quaternion with the same orientation and unit length.

Remarks

Results are undefined if the length of the quaternion is close to 0.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Converts a Mono.Simd.Vector4f to a quaternion.

Syntax

public static implicit operator Quaternion (Mono.Simd.Vector4f v)

Parameters

v
The vector to convert

Returns

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Converts a quaternion to a Mono.Simd.Vector4f.

Syntax

public static implicit operator Mono.Simd.Vector4f (Quaternion v)

Parameters

v
The quaternion to convert

Returns

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Multiply Method

Multiplies two quaternions.

Syntax

public static Quaternion operator* ([System.Runtime.CompilerServices.IsReadOnly] ref Quaternion a, [System.Runtime.CompilerServices.IsReadOnly] ref Quaternion b)

Parameters

a
The first quaternion
b
The second quaternion

Returns

Returns the composed orientation for the two quaternions.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_UnaryNegation Method

Negates a quaternion

Syntax

[System.Obsolete]
public static Quaternion operator- (Quaternion q)

Parameters

q
The quaternion to negate

Returns

Remarks

Note this is not a quaternion inverse, it is a component-wise multiplication by -1. For a quaternion inverse use Quaternion.Inverse

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Parse Method

Parse a Quaternion from a string.

Syntax

public static Quaternion Parse (string quaternionString)

Parameters

quaternionString
A string of the format "[X,Y,Z,W]"

Returns

The Quaternion parsed from quaternionString.

Exceptions

Type Reason
ArgumentException If quaternionString is null.
FormatException If the string is not a valid quaternion or its components are not valid floats.

Remarks

Example

C# Example
Quaternion myQuat = Quaternion.Parse("[0.0,0.0,0.0,1.0]");

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ShortestRotation Method

Generates the shortest rotation quaternion to rotate from one vector to another.

Syntax

public static Quaternion ShortestRotation ([System.Runtime.CompilerServices.IsReadOnly] ref Vector from, [System.Runtime.CompilerServices.IsReadOnly] ref Vector to)

Parameters

from
Vector rotating from.
to
Vector rotating to.

Returns

The corresponding quaternion.

Remarks

This function assumes that the passed in vectors are normalized.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToAngleAxis Method

Gets the angle-axis representation

Syntax

public void ToAngleAxis (out float angle, out Vector axis)

Parameters

angle
Angle of rotation in radians
axis
A normalized axis of rotation

Remarks

For the Quaternion Identity (no rotation) the axis is undefined and will be given as (0,0,1)

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

Generates a string representation of the quaternion.

Syntax

public override string ToString ()

Returns

The quaternion as a string.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

Generates a string representation of the quaternion.

Syntax

public string ToString (string format)

Parameters

format
Format to use for each of the coordinates.

Returns

The quaternion as a string.

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

TryParse Method

Try to parse a Quaternion from a string.

Syntax

public static bool TryParse (string quaternionString, out Quaternion quaternion)

Parameters

quaternionString
A string of the format "[X,Y,Z,W]"
quaternion
The quaternion that will be set if quaternionString represents a valid quaternion.

Returns

True if successfully parsed a quaternion, false if not.

Remarks

Example

C# Example
Quaternion myQuat;
            if (Quaternion.TryParse("[0.0,0.0,0.0,1.0]", out myQuat)
            {
                // myQuat is set.
            }

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

W Property

The W coordinate of the quaternion.

Syntax

public float W { get; set; }

Value

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

X Property

The X coordinate of the quaternion.

Syntax

public float X { get; set; }

Value

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Y Property

The Y coordinate of the quaternion.

Syntax

public float Y { get; set; }

Value

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Z Property

The Z coordinate of the quaternion.

Syntax

public float Z { get; set; }

Value

Remarks

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

 


 

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.