Quaternion
Quick answer
Quaternion represents a 3D rotation with four components, avoiding gimbal lock and interpolating smoothly through slerp(). Object3D stores rotation internally as a quaternion and syncs it with the Euler rotation property. Use setFromAxisAngle(), setFromEuler(), or setFromUnitVectors() to construct normalized unit orientations.
new THREE.Quaternion ( x , y , z , w )
Key points
- x, y, and z are the vector part and w is the scalar part; the default (0,0,0,1) means no rotation.
- slerp(target, t) interpolates along the shortest arc between two orientations.
- multiply() composes rotations, and order matters because quaternion multiplication is non-commutative.
Example
const forward = new THREE.Vector3(0, 0, 1);
const direction = new THREE.Vector3()
.subVectors(target, mesh.position)
.normalize();
mesh.quaternion.setFromUnitVectors(forward, direction);
const targetQuat = mesh.quaternion.clone();
mesh.quaternion.slerp(targetQuat, 0.15);const axis = new THREE.Vector3(0, 1, 0).normalize();
const delta = new THREE.Quaternion().setFromAxisAngle(axis, 0.01);
mesh.quaternion.multiply(delta);
mesh.quaternion.normalize(); // 长时间累乘后防止漂移
Notes
- Assigning components directly breaks unit length; call normalize() afterward.
- Repeated multiplication accumulates drift and needs periodic normalization.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Quaternion. https://www.jingweizhi.com/en/three/api/quaternion.html (accessed 2026-11-03).