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
FromEulerAngles (Vector) : Quaternion
Generates the corresponding quaternion.
static
FromLook (Vector, Vector) : Quaternion
Creates a new rotation with the specified direction and up vectors.
  GetEulerAngles () : Vector
Converts this rotation to a vector of euler angles
  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.
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 (Quaternion, 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 (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 (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

FromEulerAngles Method

Generates the corresponding quaternion.

Syntax

public static Quaternion FromEulerAngles (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

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

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* (Quaternion a, 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

public static Quaternion operator- (Quaternion q)

Parameters

q
The quaternion to negate

Returns

Remarks

 

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

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?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.