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

Matrix4.extractBasis()

The extractBasis() method of Matrix4 class in Three.js library is used to extract the basis vectors of the 3D coordinate system from the given matrix.

Syntax

extractBasis(xAxis, yAxis, zAxis);

Parameters

The extractBasis() method takes three parameters:

  • xAxis - An instance of Vector3 class, representing the x-axis or right-handed vector of the 3D coordinate system.
  • yAxis - An instance of Vector3 class, representing the y-axis or up vector of the 3D coordinate system.
  • zAxis - An instance of Vector3 class, representing the z-axis or forward vector of the 3D coordinate system.

Return value

The extractBasis() method does not return anything. It sets the given Vector3 objects as the basis vectors of the 3D coordinate system.

Example

const matrix = new THREE.Matrix4();
matrix.makeRotationX(Math.PI / 2);

const xAxis = new THREE.Vector3();
const yAxis = new THREE.Vector3();
const zAxis = new THREE.Vector3();

matrix.extractBasis(xAxis, yAxis, zAxis);

console.log(xAxis); // Output: Vector3(1, 0, 0)
console.log(yAxis); // Output: Vector3(0, 0, 1)
console.log(zAxis); // Output: Vector3(0, -1, 0)

In the above example, we create a rotation matrix around the x-axis by half of the pi radians. Then we call the extractBasis() method with three Vector3 objects representing the x, y, and z-axis of the 3D coordinate system. The extractBasis() method updates the xAxis, yAxis and zAxis objects with their respective vectors from the matrix.

Remarks

The extractBasis() method is a useful tool for converting orientation data from one format to another. The matrix representation of 3D orientation stored in Matrix4 can be converted to other formats like Euler angles or quaternions. The extractBasis() method can be used for this conversion by extracting the orientation vectors from the matrix and plugging them into the desired format.

See also