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.
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.
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);
All of the arguments are of type float
.
x
: This represents the -value of this vector.y
: This represents the -value of this vector.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.
const vectorOne = new THREE.Vector3(); //initializes to (0,0,0);
// or
const vectorTwo = new THREE.Vector(x,y,z);
All of the arguments are of type float
.
x
: This represents the -value of the vector.y
: This represents the -value of the vector.z
: This represents the -value of the vector.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.
const vectorOne = new THREE.Vector4(); //initializes to (0,0,0,1)
/or
const vectorTwo = new THREE.Vector4(x,y,z,w);
All arguments are of type float
.
x
: This represents the -value of the vector.y
: This represents the -value of the vector.z
: This represents the -value of the vector.w
: This represents the -value of the vector.Free Resources