# Quarterion

### Quaternion Struct

Represents a quaternion orientation.

### Syntax

public struct **Quaternion**

### Member Details

#### Quaternion Constructor

> Creates a new quaternion with the supplied values.
>
> #### Syntax
>
> public **Quaternion** (\[System.Runtime.CompilerServices.IsReadOnly] *ref* [Mono.Simd.Vector4f](http://docs.go-mono.com/?link=T%3aMono.Simd.Vector4f) v)
>
> **Parameters**
>
> > *v*
> >
> > Initializes the quaternion from a [Mono.Simd.Vector4f](http://docs.go-mono.com/?link=T%3aMono.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
>
> **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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **Dot** (\[System.Runtime.CompilerServices.IsReadOnly] *ref* [Quaternion](/latest/script-api-docs/sansar-namespace/quarterion.md) 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](/latest/script-api-docs/sansar-namespace/quarterion.md) **FromAngleAxis** ([float](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) angle, \[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) 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](/latest/script-api-docs/sansar-namespace/quarterion.md) **FromEulerAngles** (\[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) a)
>
> **Parameters**
>
> > *a*
> >
> > A vector of angles in radians.
>
> **Returns**
>
> > The corresponding quaternion.
>
> #### Remarks
>
> #### 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
>
> **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](/latest/script-api-docs/sansar-namespace/quarterion.md) **FromLookOrthoNormal** (\[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) facing, \[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) up, \[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) left)
>
> **Parameters**
>
> > *facing*
> >
> > The direction to look.
> >
> > *up*
> >
> > The up direction.
> >
> > *left*
> >
> > The left 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](/latest/script-api-docs/sansar-namespace/vector.md) **GetEulerAngles** ()
>
> **Returns**
>
> > A vector of angles in radians corresponding to this quaternion.
>
> #### Remarks
>
> #### 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](/latest/script-api-docs/sansar-namespace/quarterion.md) **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
>
> **Returns**
>
> > A quaternion inverse, such that q \* q.Inverse() == q.Inverse() \* q == 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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) this \[[int](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int32) 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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **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
>
> **Returns**
>
> > A quaternion with the same orientation and unit length.
>
> #### Remarks
>
> #### 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
>
> **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
>
> **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](/latest/script-api-docs/sansar-namespace/quarterion.md) operator\* (\[System.Runtime.CompilerServices.IsReadOnly] *ref* [Quaternion](/latest/script-api-docs/sansar-namespace/quarterion.md) a, \[System.Runtime.CompilerServices.IsReadOnly] *ref* [Quaternion](/latest/script-api-docs/sansar-namespace/quarterion.md) 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
>
> **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
>
> **Parameters**
>
> > *quaternionString*
> >
> > A string of the format "\[X,Y,Z,W]"
>
> **Returns**
>
> > The Quaternion parsed from quaternionString.
>
> **Exceptions**

| Type                                                                                          | Reason                                                                          |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| [ArgumentException](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.ArgumentException) | If quaternionString is null.                                                    |
| [FormatException](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.FormatException)     | If the string is not a valid quaternion or its components are not valid floats. |

> #### Remarks
>
> #### Example

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>Quaternion myQuat = Quaternion.Parse("[0.0,0.0,0.0,1.0]");
</code></pre></td></tr><tr><td></td></tr></tbody></table>

> #### 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](/latest/script-api-docs/sansar-namespace/quarterion.md) **ShortestRotation** (\[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) from, \[System.Runtime.CompilerServices.IsReadOnly] *ref* [Vector](/latest/script-api-docs/sansar-namespace/vector.md) to)
>
> **Parameters**
>
> > *from*
> >
> > Vector rotating from.
> >
> > *to*
> >
> > Vector rotating to.
>
> **Returns**
>
> > The corresponding quaternion.
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar\
> **Assembly:** Sansar.Script (in Sansar.Script.dll)\
> **Assembly Versions:** 1.0.0.0
>
> ***

#### ToAngleAxis Method

> Gets the angle-axis representation
>
> #### Syntax
>
> **Parameters**
>
> > *angle*
> >
> > Angle of rotation in radians
> >
> > *axis*
> >
> > A normalized axis of rotation
>
> #### 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 override [string](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.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
>
> **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
>
> **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

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><strong>C# Example</strong></td></tr><tr><td><pre><code>Quaternion myQuat;
</code></pre></td></tr></tbody></table>

```
        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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **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](http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Single) **Z** { get; set; }
>
> **Value**
>
> #### Remarks
>
> #### Requirements
>
> **Namespace:** Sansar\
> **Assembly:** Sansar.Script (in Sansar.Script.dll)\
> **Assembly Versions:** 1.0.0.0
>
> ***

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sansar.com/latest/script-api-docs/sansar-namespace/quarterion.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
