BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Quaternion.multiplyQuaternions()

The Quaternion.multiplyQuaternions() method in Three.js multiplies two input quaternions and stores the resulting quaternion in the first input quaternion.

mulitplyQuaternions( q1, q2 )

Parameters

  • q1 - The first input quaternion.
  • q2 - The second input quaternion.

Both q1 and q2 should be instances of the Quaternion class in Three.js.

Return value

This method does not return anything. Instead, the resulting quaternion is stored in the first input quaternion q1.

Description

This method multiplies two quaternions in the specified order and stores the resulting quaternion in the first input quaternion.

Quaternions are a 4-dimensional representation of rotations in Three.js. They are used to describe rotations in 3D space and can be used to smoothly interpolate between different orientations. Quaternions are defined with four components (x, y, z, w), but are often normalized to have a length of 1. The formula for quaternion multiplication is:

result = q1 * q2

Where q1 and q2 are quaternions and result is the resulting quaternion.

Example

import { Quaternion } from 'three.js';
 
const q1 = new Quaternion(0, 1, 0, 0); // represents a rotation of 180 degrees around the x-axis
const q2 = new Quaternion().setFromAxisAngle(new Vector3(1, 1, 0), Math.PI / 4); // represents a rotation of 45 degrees around the axis (1, 1, 0)
 
q1.multiplyQuaternions(q1, q2); // multiply q1 by q2 and store the result in q1
 
console.log(q1); // prints Quaternion { _x: 0.382, _y: 0.924, _z: 0, _w: 0 }

In this example, we create two quaternions q1 and q2. q1 represents a rotation of 180 degrees around the x-axis, and q2 represents a rotation of 45 degrees around the axis (1, 1, 0). We then call the multiplyQuaternions() method on q1 and pass in q1 as the first parameter and q2 as the second parameter. This multiplies q1 by q2 and stores the result in q1. Finally, we log the resulting quaternion, which represents a rotation of 225 degrees around the axis (0.382, 0.924, 0).

Notes

  • This method modifies the first input quaternion (q1) and does not create a new quaternion.
  • The order in which you multiply the quaternions matters. In general, q1 * q2 produces a different result than q2 * q1.
  • If you are interpolating between two orientations, it is recommended to use slerp (spherical linear interpolation) instead of simply multiplying quaternions.

References