# Quaternion

> Quaternions are used to represent rotations.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IEquatable\<Quaternion>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IFormattable](https://learn.microsoft.com/dotnet/api/system.iformattable)

```csharp
public struct Quaternion : IEquatable<Quaternion>, IFormattable
```

## Remarks

A quaternion is a four-tuple of real numbers \{x,y,z,w}. A quaternion is a mathematically convenient alternative to the euler angle representation. You can interpolate a quaternion without experiencing gimbal lock. You can also use a quaternion to concatenate a series of rotations into a single representation.

Unity internally uses Quaternions to represent all rotations.

In most cases, you can use existing rotations from methods such as [Transform.localRotation](/engine/6000.0/script-reference/unityengine/transform/localrotation.md) or [Transform.rotation](/engine/6000.0/script-reference/unityengine/transform/rotation.md) to construct new rotations. For example, use existing rotations to smoothly interpolate between two rotations. The most used Quaternion functions are as follows: [Quaternion.LookRotation](/engine/6000.0/script-reference/unityengine/quaternion/lookrotation.md), [Quaternion.Angle](/engine/6000.0/script-reference/unityengine/quaternion/angle.md), [Quaternion.Euler](/engine/6000.0/script-reference/unityengine/quaternion/euler.md), [Quaternion.Slerp](/engine/6000.0/script-reference/unityengine/quaternion/slerp.md), [Quaternion.FromToRotation](/engine/6000.0/script-reference/unityengine/quaternion/fromtorotation.md), and [Quaternion.identity](/engine/6000.0/script-reference/unityengine/quaternion/identity.md).

You can use the Quaternion.operator \* to rotate one rotation by another, or to rotate a vector by a rotation.

Note that Unity expects Quaternions to be normalized.

## Fields

| Value                                                            | Description                                                                                       |
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [w](/engine/6000.0/script-reference/unityengine/quaternion/w.md) | W component of the Quaternion. Do not directly modify quaternions.                                |
| [x](/engine/6000.0/script-reference/unityengine/quaternion/x.md) | X component of the Quaternion. Don't modify this directly unless you know quaternions inside out. |
| [y](/engine/6000.0/script-reference/unityengine/quaternion/y.md) | Y component of the Quaternion. Don't modify this directly unless you know quaternions inside out. |
| [z](/engine/6000.0/script-reference/unityengine/quaternion/z.md) | Z component of the Quaternion. Don't modify this directly unless you know quaternions inside out. |

## Constructors

| Constructor                                                                                                                           | Description                                              |
| ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| [Quaternion(System.Single,System.Single,System.Single,System.Single)](/engine/6000.0/script-reference/unityengine/quaternion/ctor.md) | Constructs new Quaternion with given x,y,z,w components. |

## Properties

| Property                                                                             | Description                                                                 |
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
| [eulerAngles](/engine/6000.0/script-reference/unityengine/quaternion/eulerangles.md) | Returns or sets the euler angle representation of the rotation in degrees.  |
| [this\[\]](/engine/6000.0/script-reference/unityengine/quaternion/item.md)           | Access the x, y, z, w components using \[0], \[1], \[2], \[3] respectively. |
| [normalized](/engine/6000.0/script-reference/unityengine/quaternion/normalized.md)   | Returns this quaternion with a magnitude of 1 (Read Only).                  |

## Static Properties

| Property                                                                       | Description                        |
| ------------------------------------------------------------------------------ | ---------------------------------- |
| [identity](/engine/6000.0/script-reference/unityengine/quaternion/identity.md) | The identity rotation (Read Only). |

## Methods

| Method                                                                                           | Description                                                                                     |
| ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| [Equals](/engine/6000.0/script-reference/unityengine/quaternion/equals.md)                       | Performs exact binary comparison of each Quaternion component (x, y, z, w).                     |
| [Normalize](/engine/6000.0/script-reference/unityengine/quaternion/normalize.md)                 | Converts this quaternion to a quaternion with the same orientation but with a magnitude of 1.0. |
| [Set](/engine/6000.0/script-reference/unityengine/quaternion/set.md)                             | Set x, y, z and w components of an existing Quaternion.                                         |
| [SetFromToRotation](/engine/6000.0/script-reference/unityengine/quaternion/setfromtorotation.md) | Creates a rotation which rotates from fromDirection to toDirection.                             |
| [SetLookRotation](/engine/6000.0/script-reference/unityengine/quaternion/setlookrotation.md)     | Creates a rotation with the specified forward and upwards directions.                           |
| [ToAngleAxis](/engine/6000.0/script-reference/unityengine/quaternion/toangleaxis.md)             | Converts a rotation to angle-axis representation.                                               |
| [ToString](/engine/6000.0/script-reference/unityengine/quaternion/tostring.md)                   | Returns a formatted string for this quaternion.                                                 |

## Static Methods

| Method                                                                                     | Description                                                                                             |
| ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| [Angle](/engine/6000.0/script-reference/unityengine/quaternion/angle.md)                   | Returns the angle in degrees between two rotations a and b. The resulting angle ranges from 0 to 180.   |
| [AngleAxis](/engine/6000.0/script-reference/unityengine/quaternion/angleaxis.md)           | Creates a rotation which rotates `angle` degrees around `axis`.                                         |
| [Dot](/engine/6000.0/script-reference/unityengine/quaternion/dot.md)                       | The dot product between two rotations.                                                                  |
| [Euler](/engine/6000.0/script-reference/unityengine/quaternion/euler.md)                   | Converts an input Euler angle rotation specified as three floats to a Quaternion.                       |
| [FromToRotation](/engine/6000.0/script-reference/unityengine/quaternion/fromtorotation.md) | Creates a rotation from fromDirection to toDirection.                                                   |
| [Inverse](/engine/6000.0/script-reference/unityengine/quaternion/inverse.md)               | Returns the Inverse of rotation.                                                                        |
| [Lerp](/engine/6000.0/script-reference/unityengine/quaternion/lerp.md)                     | Interpolates between a and b by t and normalizes the result afterwards.                                 |
| [LerpUnclamped](/engine/6000.0/script-reference/unityengine/quaternion/lerpunclamped.md)   | Interpolates between a and b by t and normalizes the result afterwards. The parameter t is not clamped. |
| [LookRotation](/engine/6000.0/script-reference/unityengine/quaternion/lookrotation.md)     | Creates a rotation with the specified `forward` and `upwards` directions.                               |
| [Normalize](/engine/6000.0/script-reference/unityengine/quaternion/normalize.md)           | Converts this quaternion to a quaternion with the same orientation but with a magnitude of 1.0.         |
| [RotateTowards](/engine/6000.0/script-reference/unityengine/quaternion/rotatetowards.md)   | Rotates a rotation from towards to.                                                                     |
| [Slerp](/engine/6000.0/script-reference/unityengine/quaternion/slerp.md)                   | Spherically linear interpolates between unit quaternions a and b by a ratio of t.                       |
| [SlerpUnclamped](/engine/6000.0/script-reference/unityengine/quaternion/slerpunclamped.md) | Spherically linear interpolates between unit quaternions a and b by t.                                  |

## Operators

| Operator                                                                             | Description                              |
| ------------------------------------------------------------------------------------ | ---------------------------------------- |
| [operator ==](/engine/6000.0/script-reference/unityengine/quaternion/op-equality.md) | Are two quaternions equal to each other? |
| [operator \*](/engine/6000.0/script-reference/unityengine/quaternion/op-multiply.md) | Combines rotations lhs and rhs.          |
