new Vector4(x, y, z, z)
A class which provides 4D vector.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number | The vector's x value. |
y |
Number | The vector's y value. |
z |
Number | The vector's z value. |
z |
Number | The vector's w value. |
- Since:
-
- 2.1.0
Example
var Vector4 = caph.math.Vector4; var vecA = new Vector4(10, 10, 0, 0);
Methods
-
add(vector) → {caph.math.Vector4}
-
Adds the given vector with this vector.
Parameters:
Name Type Description vectorcaph.math.Vector4 A vector4 to add.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = new Vector4(1, 5, 1, 5); vecA.add(vecB); -
applyMatrix4(matrix) → {caph.math.Vector4}
-
Multiplies this vector by 4 x 4 subset of a Matrix4.
Parameters:
Name Type Description matrixArray | caph.math.Matrix4 A matrix to multiply.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var Matrix4 = caph.require('math.Matrix4'); var vecA = new Vector4(10, 10, 0, 0); var matA = new Matrix4([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]); vecA.applyMatrix4(matA); -
clone() → {caph.math.Vector4}
-
Creates a copy of this vector.
- Since:
-
- 2.1.0
Returns:
vector4
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = vecA.clone(); -
distance(vector) → {Number}
-
Calculates the distance between this and the given vector.
Parameters:
Name Type Description vectorcaph.math.Vector4 Operand vector to calculate distance
- Since:
-
- 2.1.0
Returns:
- Type
- Number
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = new Vector4(1, 5, 1, 5); var distance = vecA.distance(vecB); -
divide(vector) → {caph.math.Vector4}
-
Divides this vector by the given vector.
Parameters:
Name Type Description vectorcaph.math.Vector4 A vector4 to multiply.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = new Vector4(1, 5, 1, 5); vecA.divide(vecB); -
dot(vector) → {Number}
-
Calculates the dot product of this and the given vector.
Parameters:
Name Type Description vectorcaph.math.Vector4 Operand vector
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- Number
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = new Vector4(1, 5, 1, 5); var dot = vecA.dot(vecB); -
get() → {Array}
-
Gets value of this vector.
- Since:
-
- 2.1.0
Returns:
[x, y, z, w]
- Type
- Array
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vec = vecA.get(); var x = vec[0]; var y = vec[1]; var z = vec[2]; var w = vec[3]; -
length() → {Number}
-
Calculates the length of a vector.
- Since:
-
- 2.1.0
Returns:
- Type
- Number
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var length = vecA.length(); -
multiply(vector) → {caph.math.Vector4}
-
Multiplies this vector and the given vector.
Parameters:
Name Type Description vectorcaph.math.Vector4 A vector4 to multiply.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = new Vector4(1, 5, 1, 5); vecA.multiply(vecB); -
multiplyScalar(scalar) → {caph.math.Vector4}
-
Multiplies this vector and scalar quantity.
Parameters:
Name Type Description scalarNumber Scalar to multiply with vector.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); vecA.multiplyScalar(2); -
normalize() → {caph.math.Vector4}
-
Normalizes a vector.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); vecA.normalize(); -
set(x, y, z, w) → {caph.math.Vector4}
-
Sets value of this vector.
Parameters:
Name Type Description xNumber The vector's x value.
yNumber The vector's y value.
zNumber The vector's z value.
wNumber The vector's w value.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(); vecA.set(10, 10, 0, 0); -
subtract(vector) → {caph.math.Vector4}
-
Subtracts the given vector from this vector.
Parameters:
Name Type Description vectorcaph.math.Vector4 A vector4 to subtract.
- Since:
-
- 2.1.0
Returns:
This vector itself.
- Type
- caph.math.Vector4
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = new Vector4(1, 5, 1, 5); vecA.subtract(vecB); -
toVector3() → {caph.math.Vector3}
-
Creates a copy of this vector.
- Since:
-
- 2.1.0
Returns:
vector
- Type
- caph.math.Vector3
Example
var Vector4 = caph.require('math.Vector4'); var vecA = new Vector4(10, 10, 0, 0); var vecB = vecA.toVector3();