DeepAR Scripting API v5.6.12

Class: Vector3

Vector3(…params)

Represents a three-dimensional vector.

Constructor

new Vector3(…params)

Constructs a new three-dimensional vector.
Parameters:
Name Type Attributes Description
params any <repeatable>
Dimensional values. See the examples below.
Examples
// Creates a (0, 0, 0) vector.
var vec = new Vector3();
// Creates a (6.9, 6.9, 6.9) vector.
var vec = new Vector3(6.9);
// Creates a (4, 6, 2.5) vector.
var vec = new Vector3(4, 6, 2.5);
// Expands a two-dimensional (1, 2) vector into three-dimensional (1, 2, 3) vector.
var baseVec = new Vector2(1, 2);
var vec = new Vector3(baseVec, 3);
// Copies a (1, 2, 3) vector.
var originalVec = new Vector3(1, 2, 3);
var vec = new Vector3(originalVec);
// Truncates a four-dimensional (1, 2, 3, 4) vector into three-dimensional (1, 2, 3) vector.
var baseVec = new Vector4(1, 2, 3, 4);
var vec = new Vector3(baseVec);

Members

length :double

The length of the vector.
Type:
  • double

(readonly) normalized :Vector3

Gets the normalized vector.
Type:

x :double

The X-dimensional value of the vector.
Type:
  • double

y :double

The Y-dimensional value of the vector.
Type:
  • double

z :double

The Z-dimensional value of the vector.
Type:
  • double

Methods

add(param) → {Vector3}

Adds the vector instance and a number or another vector.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Adds (1, 2, 3) and (3, 2, 1), which results in (4, 4, 4).
var vec = new Vector3(1, 2, 3);
var result = vec.add(new Vector3(3, 2, 1));
// Adds (1, 2, 3) and 3, which results in (4, 5, 6).
var vec = new Vector3(1, 2, 3);
var result = vec.add(3);

clone() → {Vector3}

Clones the vector.
Returns:
Vector clone.
Type
Vector3

div(param) → {Vector3}

Divides the vector instance and a number or another vector. Same as Vector3.divide() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Divides (1, 2, 3) and (3, 2, 1), which results in (0.33333..., 1, 3).
var vec = new Vector3(1, 2, 3);
var result = vec.div(new Vector3(3, 2, 1));
// Divides (1, 2, 3) and 3, which results in (0.33333..., 0.66666..., 1).
var vec = new Vector3(1, 2, 3);
var result = vec.div(3);

divide(param) → {Vector3}

Divides the vector instance and a number or another vector. Same as Vector3.div() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Divides (1, 2, 3) and (3, 2, 1), which results in (0.33333..., 1, 3).
var vec = new Vector3(1, 2, 3);
var result = vec.divide(new Vector3(3, 2, 1));
// Divides (1, 2, 3) and 3, which results in (0.33333..., 0.66666..., 1).
var vec = new Vector3(1, 2, 3);
var result = vec.divide(3);

equals(vector, epsilonopt) → {bool}

Compares the vector instance with another vector and checks if they are equal.
Parameters:
Name Type Attributes Default Description
vector Vector3 Another three-dimensional vector.
epsilon double <optional>
1e-6 Epsilon tolerance.
Returns:
True if equal, false otherwise.
Type
bool
Examples
// Outputs 'false' to the debug console.
var a = new Vector3(1, 1, 1);
var b = new Vector3(1, 1, 1.001);
Debug.log(a.equals(b).toString());
// Outputs 'true' to the debug console.
var a = new Vector3(1, 1, 1);
var b = new Vector3(1, 1, 1.001);
Debug.log(a.equals(b, 0.01).toString());

mod(param) → {Vector3}

Reduces the modulo of dividing the vector instance and a number or another vector. Same as Vector3.modulo() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Reduces the modulo of dividing (1, 2, 3) and (3, 2, 1), which results in (1, 0, 0).
var vec = new Vector3(1, 2, 3);
var result = vec.mod(new Vector3(3, 2, 1));
// Reduces the modulo of dividing (1, 2, 3) and 3, which results in (1, 2, 0).
var vec = new Vector3(1, 2, 3);
var result = vec.mod(3);

modulo(param) → {Vector3}

Reduces the modulo of dividing the vector instance and a number or another vector. Same as Vector3.mod() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Reduces the modulo of dividing (1, 2, 3) and (3, 2, 1), which results in (1, 0, 0).
var vec = new Vector3(1, 2, 3);
var result = vec.modulo(new Vector3(3, 2, 1));
// Reduces the modulo of dividing (1, 2, 3) and 3, which results in (1, 2, 0).
var vec = new Vector3(1, 2, 3);
var result = vec.modulo(3);

mul(param) → {Vector3}

Multiplies the vector instance and a number or another vector. Same as Vector3.multiply() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Multiplies (1, 2, 3) and (3, 2, 1), which results in (3, 4, 3).
var vec = new Vector3(1, 2, 3);
var result = vec.mul(new Vector3(3, 2, 1));
// Multiplies (1, 2, 3) and 3, which results in (3, 6, 9).
var vec = new Vector3(1, 2, 3);
var result = vec.mul(3);

multiply(param) → {Vector3}

Multiplies the vector instance and a number or another vector. Same as Vector3.mul() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Multiplies (1, 2, 3) and (3, 2, 1), which results in (3, 4, 3).
var vec = new Vector3(1, 2, 3);
var result = vec.multiply(new Vector3(3, 2, 1));
// Multiplies (1, 2, 3) and 3, which results in (3, 6, 9).
var vec = new Vector3(1, 2, 3);
var result = vec.multiply(3);

sub(param) → {Vector3}

Subtracts the vector instance and a number or another vector. Same as Vector3.subtract() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Subtracts (1, 2, 3) and (3, 2, 1), which results in (-2, 0, 2).
var vec = new Vector3(1, 2, 3);
var result = vec.sub(new Vector3(3, 2, 1));
// Subtracts (1, 2, 3) and 3, which results in (-2, -1, 0).
var vec = new Vector3(1, 2, 3);
var result = vec.sub(3);

subtract(param) → {Vector3}

Subtracts the vector instance and a number or another vector. Same as Vector3.sub() method.
Parameters:
Name Type Description
param double | Vector3 A number or a three-dimensional vector.
Returns:
New vector containing the result.
Type
Vector3
Examples
// Subtracts (1, 2, 3) and (3, 2, 1), which results in (-2, 0, 2).
var vec = new Vector3(1, 2, 3);
var result = vec.subtract(new Vector3(3, 2, 1));
// Subtracts (1, 2, 3) and 3, which results in (-2, -1, 0).
var vec = new Vector3(1, 2, 3);
var result = vec.subtract(3);

toString() → {string}

Gets the string representation of a vector instance.
Returns:
Vector string representation.
Type
string
Example
// Outputs '[Vector3 (6, -1, 4)]' to the debug console.
var vec = new Vector3(6, -1, 4);
Debug.log(vec.toString());

toVec2(homogeneousDivideopt) → {Vector2}

Creates a new two-dimensional vector instance by truncating this vector instance. Same as Vector3.toVector2() method.
Parameters:
Name Type Attributes Default Description
homogeneousDivide bool <optional>
false If true, the remaining two dimensional values will be divided by the Z-dimensional value.
Returns:
Two-dimensional vector.
Type
Vector2
Examples
// Creates a (-2, 4) vector from (-2, 4, 2) vector.
var a = new Vector3(-2, 4, 2);
var b = a.toVec2();
// Creates a (-1, 2) vector from (-2, 4, 2) vector (homogeneous division).
var a = new Vector3(-2, 4, 2);
var b = a.toVec2(true);

toVec4(w) → {Vector4}

Creates a new four-dimensional vector instance by extending this vector instance. Same as Vector3.toVector4() method.
Parameters:
Name Type Description
w double The W-dimensional value of the vector.
Returns:
Four-dimensional vector.
Type
Vector4
Example
// Creates a (-2, 4, 2, 5) vector from (-2, 4, 2) vector.
var a = new Vector3(-2, 4, 2);
var b = a.toVec4(5);

toVector2(homogeneousDivideopt) → {Vector2}

Creates a new two-dimensional vector instance by truncating this vector instance. Same as Vector3.toVec2() method.
Parameters:
Name Type Attributes Default Description
homogeneousDivide bool <optional>
false If true, the remaining two dimensional values will be divided by the Z-dimensional value.
Returns:
Two-dimensional vector.
Type
Vector2
Examples
// Creates a (-2, 4) vector from (-2, 4, 2) vector.
var a = new Vector3(-2, 4, 2);
var b = a.toVector2();
// Creates a (-1, 2) vector from (-2, 4, 2) vector (homogeneous division).
var a = new Vector3(-2, 4, 2);
var b = a.toVector2(true);

toVector4(w) → {Vector4}

Creates a new four-dimensional vector instance by extending this vector instance. Same as Vector3.toVec4() method.
Parameters:
Name Type Description
w double The W-dimensional value of the vector.
Returns:
Four-dimensional vector.
Type
Vector4
Example
// Creates a (-2, 4, 2, 5) vector from (-2, 4, 2) vector.
var a = new Vector3(-2, 4, 2);
var b = a.toVector4(5);