# base/quaternion (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/base/quaternion/

Quaternion. (3D rotation, the basic unit of skeletal animation interpolation)

## Quaternion extends Object

Quaternion. (3D rotation, the basic unit of skeletal animation interpolation)

Example: Interpolate between two rotations and rotate a direction

```js
import { Quaternion, Matrix4 } from "./build/vanilla.js";

const start = Quaternion.identity();
const end = Quaternion.createFromEuler(0, Math.PI / 2, 0);
const halfway = Quaternion.slerp(start, end, 0.5);
console.log(halfway.x, halfway.y, halfway.z, halfway.w);
const rotation = Matrix4.createRotationFromQuaternion(halfway);
const direction = rotation.transformDirection(0, 0, 1);
console.log(direction.x, direction.y, direction.z);
```

- `constructor()` (constructor, since 0.3.0): Constructor.
- `clone()` (method, since 0.3.0): Clone.
  - returns this: A new quaternion with the same components.
- `get/set x` (property, since 0.3.0): X component getter property.
  X component setter property.
  - returns number: X component.
- `get/set y` (property, since 0.3.0): Y component getter property.
  Y component setter property.
  - returns number: Y component.
- `get/set z` (property, since 0.3.0): Z component getter property.
  Z component setter property.
  - returns number: Z component.
- `get/set w` (property, since 0.3.0): W component getter property.
  W component setter property.
  - returns number: W component.
- `set(x, y, z, w)` (method, since 0.3.0): Assignment.
  - `x` number: X component.
  - `y` number: Y component.
  - `z` number: Z component.
  - `w` number: W component.
- `normalize()` (method, since 0.3.0): Normalize.
  - returns Quaternion: A new quaternion scaled to length 1. (identity if the length is 0)
- `multiply(other)` (method, since 0.3.0): Multiply. (Accumulates the other rotation locally after this rotation)
  - `other` Quaternion: Rotation to apply after.
  - returns Quaternion: A new quaternion combining both rotations. (this × other)
- `static create(x, y, z, w)` (static, since 0.3.0): Creates. (static)
  - `x` number: X component.
  - `y` number: Y component.
  - `z` number: Z component.
  - `w` number: W component.
  - returns Quaternion: A new quaternion.
- `static identity()` (static, since 0.3.0): Creates an identity quaternion. (static)
  - returns Quaternion: A (0, 0, 0, 1) quaternion with no rotation.
- `static createFromEuler(xRadian, yRadian, zRadian)` (static, since 0.3.0): Creates from Euler angles. (static, XYZ order, radians)
  - `xRadian` number: Rotation around the X axis. (radians)
  - `yRadian` number: Rotation around the Y axis. (radians)
  - `zRadian` number: Rotation around the Z axis. (radians)
  - returns Quaternion: Rotation quaternion.
- `static slerp(from, to, normalizedTime)` (static, since 0.3.0): Spherical linear interpolation. (static, shortest path)
  - `from` Quaternion: Start rotation.
  - `to` Quaternion: End rotation.
  - `normalizedTime` number: 0 gives from, 1 gives to.
  - returns Quaternion: A new interpolated and normalized quaternion. (takes the shorter path)
