Creates a new Vector3. Accepts any arguments that RS.Math.Vector3#set accepts.
Name | Type | Description |
---|---|---|
initial |
RS.Math.Vector3 | Array | Object | Number |
optional
initial value. |
Example
let v = new RS.Math.Vector3();
v = new RS.Math.Vector3(1,2,3);
v = new RS.Math.Vector3([0.2,-0.3,0.5]);
v = new RS.Math.Vector3({x: 0.1, y: 0.53, z: -0.2});
Members
-
The X component of the vector
-
The Y component of the vector
-
The Z component of the vector
Methods
-
add (rhs)RS.Math.Vector3
-
Adds another vector to this vector.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector
Returns:
Type Description RS.Math.Vector3 this Example
const vec = new RS.Math.Vector3(1,2,3); vec.add(new RS.Math.Vector3(7,-3,0)); // vec is now {x:8,y:-1,z:3}
-
clone ()RS.Math.Vector3
-
returns a copy of this vector.
Returns:
Type Description RS.Math.Vector3 -
cross (rhs)RS.Math.Vector3
-
Returns the cross product between this vector and another.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector.
Returns:
Type Description RS.Math.Vector3 the cross product -
Returns the distance between the point specified by this vector and another
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector.
Returns:
Type Description Number the distance -
divide (rhs)RS.Math.Vector3
-
Divides another vector into this vector per-component.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector
Returns:
Type Description RS.Math.Vector3 this Example
const vec = new RS.Math.Vector3(1,2,3); vec.divide(new RS.Math.Vector3(7,-3,1)); // vec is now {x:0.1428,y:-0.6667,z:3}
-
Returns the dot product between this vector and another.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector.
Returns:
Type Description Number the dot product -
Returns whether this vector is equal to another vector.
Name Type Description rhs
RS.Math.Vector3 the vector to compare to
tolerance
Number optional if provided then this level of tolerance is used.
Returns:
Type Description Boolean true
if equal,false
if notExample
let vec = new RS.Math.Vector3(0.01,-0.05,0.03); vec.equal(vec); // returns true vec.equal(new RS.Math.Vector3(0.02,-0.05,0.03)); // returns false vec.equal(new RS.Math.Vector3(0.02,-0.05,0.03),0.1); // returns true due to tolerance
-
Returns whether this vector is equal to another vector within a tolerance.
Name Type Description rhs
RS.Math.Vector3 the vector to compare to
tolerance
Number optional if provided then this level of tolerance is used, otherwise tolerance is
10e-5
Returns:
Type Description Boolean true
if equal,false
if notExample
let vec = new RS.Math.Vector3(0.01,-0.05,0.03); vec.equal_with_tolerance(vec); // returns true vec.equal_with_tolerance(new RS.Math.Vector3(0.02,-0.05,0.03)); // returns false vec.equal_with_tolerance(new RS.Math.Vector3(0.01001,-0.05,0.03)); // returns true due to default tolerance vec.equal_with_tolerance(new RS.Math.Vector3(0.02,-0.05,0.03),0.1); // returns true due to tolerance
-
Returns whether this vector and another are colinear (point in the same direction.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector
Returns:
Type Description Boolean true
if colinear,false
if notExample
const vec = new RS.Math.Vector3(1,2,3); vec.is_colinear(new RS.Math.Vector3(2,4,6)); // returns true vec.is_colinear(new RS.Math.Vector3(1,0,0)); // returns false vec.is_colinear(new RS.Math.Vector3(-2,-4,-6)); // returns false since they point in opposite directions
-
Returns whether this vector is the null vector
Name Type Description tolerance
Number optional if provided then this level of tolerance is used.
Returns:
Type Description Boolean true
if null,false
if notExample
let vec = new RS.Math.Vector3(0.01,-0.05,0.03); vec.is_null_vector(); // returns false vec.is_null_vector(0.1); // returns true due to tolerance vec = new RS.Math.Vector3(); vec.is_null_vector(); // returns true
-
Returns the length of this vector.
Returns:
Type Description Number the length -
multiply (rhs)RS.Math.Vector3
-
Multiplies another vector with this vector per-component.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector
Returns:
Type Description RS.Math.Vector3 this Example
const vec = new RS.Math.Vector3(1,2,3); vec.multiply(new RS.Math.Vector3(7,-3,1)); // vec is now {x:7,y:-6,z:3}
-
normalize ()RS.Math.Vector3
-
Normalizes this vector.
Returns:
Type Description RS.Math.Vector3 this -
rotate (matrix)RS.Math.Vector3
-
Rotates this vector by multiplying the provided matrix on the right hand side.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
Returns:
Type Description RS.Math.Vector3 this -
rotate_to (matrix, out)RS.Math.Vector3
-
Rotates this vector by multiplying the provided matrix on the right hand side and copies the result into the out vector. This vector is not modified.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
out
RS.Math.Vector3 optional The vector to receive the result. If not provided a new vector is created.
Returns:
Type Description RS.Math.Vector3 the transformed vector. -
rotate_transpose (matrix)RS.Math.Vector3
-
Rotates this vector by multiplying the transpose of the provided matrix on the right hand side.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
Returns:
Type Description RS.Math.Vector3 this -
rotate_transpose_to (matrix, out)RS.Math.Vector3
-
Rotates this vector by multiplying the transpose of the provided matrix on the right hand side and copies the result into the out vector. This vector is not modified.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
out
RS.Math.Vector3 optional The vector to receive the result. If not provided a new vector is created.
Returns:
Type Description RS.Math.Vector3 the transformed vector. -
scale (scale)RS.Math.Vector3
-
Uniformly scales this vector.
Name Type Description scale
Number the scaling factor
Returns:
Type Description RS.Math.Vector3 this Example
const vec = new RS.Math.Vector3(1,2,3); vec.scale(2); // vec is now {x:2,y:4,z:6}
-
Sets this vector. The source may be of the following types:
- RS.Math.Vector3
- an
Array
with 3 or more members - an
Object
. - individual arguments for
x
,y
andz
In the case of an object being supplied it should have the members
x
,y
,z
. Parsing failures onx
,y
orz
will set them to0
.Name Type Description source
RS.Math.Vector3 | Array | Object | Number the object to set from or a set of numbers.
Example
const v = new RS.Math.Vector3(); v.set(1,2,3); v.set([0.2,-0.3,0.5]); v.set({x: 0.1, y: 0.53, z: -0.2});
-
subtract (rhs)RS.Math.Vector3
-
Subtracts another vector from this vector.
Name Type Description rhs
RS.Math.Vector4 | RS.Math.Vector3 the other vector
Returns:
Type Description RS.Math.Vector3 this Example
const vec = new RS.Math.Vector3(1,2,3); vec.subtract(new RS.Math.Vector3(7,-3,0)); // vec is now {x:-6,y:5,z:3}
-
Returns a string describing this Object.
Returns:
Type Description String A String describing this Object. -
transform (matrix)RS.Math.Vector3
-
Transforms this vector by multiplying the provided matrix on the right hand side.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
Returns:
Type Description RS.Math.Vector3 this -
transform_to (matrix, out)RS.Math.Vector3
-
Transforms this vector by multiplying the provided matrix on the right hand side and copies the result into the out vector. This vector is not modified.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
out
RS.Math.Vector3 optional The vector to receive the result. If not provided a new vector is created.
Returns:
Type Description RS.Math.Vector3 the transformed vector. -
transform_transpose (matrix)RS.Math.Vector3
-
Transforms this vector by multiplying the transpose of the provided matrix on the right hand side.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
Returns:
Type Description RS.Math.Vector3 this -
transform_transpose_to (matrix, out)RS.Math.Vector3
-
Transforms this vector by multiplying the transpose of the provided matrix on the right hand side and copies the result into the out vector. This vector is not modified.
Name Type Description matrix
RS.Math.Matrix4x4 The matrix to transform the vector by.
out
RS.Math.Vector3 optional The vector to receive the result. If not provided a new vector is created.
Returns:
Type Description RS.Math.Vector3 the transformed vector.