# base/quaternion (vanilla.js 0.4.0)

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

쿼터니언. (3차원 회전, 골격 애니메이션 보간의 기본 단위)

## Quaternion extends Object

쿼터니언. (3차원 회전, 골격 애니메이션 보간의 기본 단위)

예제: 두 회전 사이를 보간해 방향 돌리기

```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): 생성.
- `clone()` (method, since 0.3.0): 복제.
  - returns this: 성분이 같은 새 쿼터니언.
- `get/set x` (property, since 0.3.0): X 성분 반환 프로퍼티.
  X 성분 설정 프로퍼티.
  - returns number: X 성분.
- `get/set y` (property, since 0.3.0): Y 성분 반환 프로퍼티.
  Y 성분 설정 프로퍼티.
  - returns number: Y 성분.
- `get/set z` (property, since 0.3.0): Z 성분 반환 프로퍼티.
  Z 성분 설정 프로퍼티.
  - returns number: Z 성분.
- `get/set w` (property, since 0.3.0): W 성분 반환 프로퍼티.
  W 성분 설정 프로퍼티.
  - returns number: W 성분.
- `set(x, y, z, w)` (method, since 0.3.0): 대입.
  - `x` number: X 성분.
  - `y` number: Y 성분.
  - `z` number: Z 성분.
  - `w` number: W 성분.
- `normalize()` (method, since 0.3.0): 정규화.
  - returns Quaternion: 길이를 1 로 맞춘 새 쿼터니언. (길이가 0 이면 단위 쿼터니언)
- `multiply(other)` (method, since 0.3.0): 곱하기. (this 회전 뒤에 other 회전을 로컬로 누적)
  - `other` Quaternion: 뒤에 이을 회전.
  - returns Quaternion: 두 회전을 합친 새 쿼터니언. (this × other)
- `static create(x, y, z, w)` (static, since 0.3.0): 생성. (정적)
  - `x` number: X 성분.
  - `y` number: Y 성분.
  - `z` number: Z 성분.
  - `w` number: W 성분.
  - returns Quaternion: 새 쿼터니언.
- `static identity()` (static, since 0.3.0): 단위 쿼터니언 생성. (정적)
  - returns Quaternion: 회전이 없는 (0, 0, 0, 1) 쿼터니언.
- `static createFromEuler(xRadian, yRadian, zRadian)` (static, since 0.3.0): 오일러 각으로 생성. (정적, XYZ 순서 라디안)
  - `xRadian` number: X 축 회전. (라디안)
  - `yRadian` number: Y 축 회전. (라디안)
  - `zRadian` number: Z 축 회전. (라디안)
  - returns Quaternion: 회전 쿼터니언.
- `static slerp(from, to, normalizedTime)` (static, since 0.3.0): 구면 선형 보간. (정적, 최단 경로)
  - `from` Quaternion: 시작 회전.
  - `to` Quaternion: 끝 회전.
  - `normalizedTime` number: 0 이면 from, 1 이면 to.
  - returns Quaternion: 보간해 정규화한 새 쿼터니언. (짧은 쪽으로 돈다)
