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