What are the different vector classes in Three.js?

Overview

Three.js is a JavaScript library that is built on top of WebGL and is used for rendering animations on the web.

It provides the use of multi-dimensional vectors. These include the following:

  • Vector2

  • Vector3

  • Vector4

There are different methods and properties in three.js that make use of these vectors. For example, quaternions in Three.js use Vector4 to represent rotations.

Vector2

This class of vectors represents a two-dimensional vector. A two-dimensional vector can, in turn, be used to represent the following:

  • A 2-D point in space.

  • The length and direction inside the plane.

  • An arbitrary ordered pair of numbers.

Syntax

Below is the syntax for initializing a Vector2.

const vectorOne = new THREE.Vector2(); //initializes to (0,0);

// or

const vectorTwo = new THREE.Vector2(x,y);

Parameters

All of the arguments are of type float.

  • x: This represents the xx-value of this vector.
  • y: This represents the yy-value of this vector.

Vector3

This class of vectors represents a three-dimensional vector. A three-dimensional vector can represent the following:

  • A 3-D point in space.

  • The three-dimensional distance from one point to another.

  • An arbitrary ordered triplet of numbers.

Syntax

const vectorOne = new THREE.Vector3(); //initializes to (0,0,0);

// or

const vectorTwo = new THREE.Vector(x,y,z);

Parameters

All of the arguments are of type float.

  • x: This represents the xx-value of the vector.
  • y: This represents the yy-value of the vector.
  • z: This represents the zz-value of the vector.

Vector4

This class represents four-dimensional vectors. A four-dimensional vector can be used for the following purposes:

  • A 4-D point in space.

  • The length and direction from one point to another in four-dimensional space.

  • An arbitrary ordered quadruplet of numbers.

Syntax

const vectorOne = new THREE.Vector4(); //initializes to (0,0,0,1)

/or

const vectorTwo = new THREE.Vector4(x,y,z,w);

Parameters

All arguments are of type float.

  • x: This represents the xx-value of the vector.
  • y: This represents the yy-value of the vector.
  • z: This represents the zz-value of the vector.
  • w: This represents the ww-value of the vector.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved