new Vector(opt_x, opt_y)
Creates a new Vector.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
opt_x |
number |
<optional> |
0 | The x location. |
opt_y |
number |
<optional> |
0 | The y location. |
- Source:
Methods
-
<static> VectorAdd(v1, v2) → {Object}
-
Add two vectors.
Parameters:
Name Type Description v1
number The first vector. v2
number The second vector. - Source:
Returns:
A new Vector.- Type
- Object
-
<static> VectorAngleBetween(v1, v2) → {number}
-
Get the angle between two vectors.
Parameters:
Name Type Description v1
number The first vector. v2
number The second vector. - Source:
Returns:
An angle.- Type
- number
-
<static> VectorDistance(v1, v2) → {number}
-
Calculates the distance between two vectors.
Parameters:
Name Type Description v1
number The first vector. v2
number The second vector. - Source:
Returns:
The distance between the two vectors.- Type
- number
-
<static> VectorDiv(v, n) → {Object}
-
Divide two vectors.
Parameters:
Name Type Description v
number A vector. n
number Vector will be divided by this number. - Source:
Returns:
A new Vector.- Type
- Object
-
<static> VectorMidPoint(v1, v2) → {Object}
-
Get the midpoint between two vectors.
Parameters:
Name Type Description v1
number The first vector. v2
number The second vector. - Source:
Returns:
A new Vector.- Type
- Object
-
<static> VectorMult(v, n) → {Object}
-
Multiply a vector by a scalar value.
Parameters:
Name Type Description v
number A vector. n
number Vector will be multiplied by this number. - Source:
Returns:
A new Vector.- Type
- Object
-
<static> VectorSub(v1, v2) → {Object}
-
Subtract two vectors.
Parameters:
Name Type Description v1
number The first vector. v2
number The second vector. - Source:
Returns:
A new Vector.- Type
- Object
-
add(vector) → {Object}
-
Adds a vector to this vector.
Parameters:
Name Type Description vector
Object The vector to add. - Source:
Returns:
This vector.- Type
- Object
-
clone() → {Object}
-
Returns an new vector with all properties and methods of the old vector copied to the new vector's prototype.
- Source:
Returns:
A vector.- Type
- Object
-
distance(vector) → {Object}
-
Calculates the distance between this vector and a passed vector.
Parameters:
Name Type Description vector
Object The target vector. - Source:
Returns:
The distance between the two vectors.- Type
- Object
-
div(n) → {Object}
-
Divides this vector by a passed value.
Parameters:
Name Type Description n
number Vector will be divided by this number. - Source:
Returns:
This vector.- Type
- Object
-
dot(vector) → {Object}
-
Calulates the dot product.
Parameters:
Name Type Description vector
Object The target vector. - Source:
Returns:
A vector.- Type
- Object
-
limit(opt_high, opt_low) → {Object}
-
Limits the vector's magnitude.
Parameters:
Name Type Description opt_high
number The upper bound of the vector's magnitude opt_low
number The lower bound of the vector's magnitude. - Source:
Returns:
This vector.- Type
- Object
-
mag() → {number}
-
Calculates the magnitude of this vector.
- Source:
Returns:
The vector's magnitude.- Type
- number
-
midpoint(v1, v1) → {Object}
-
Calculates the midpoint between this vector and a passed vector.
Parameters:
Name Type Description v1
Object The first vector. v1
Object The second vector. - Source:
Returns:
A vector representing the midpoint between the passed vectors.- Type
- Object
-
mult(n) → {Object}
-
Multiplies this vector by a passed value.
Parameters:
Name Type Description n
number Vector will be multiplied by this number. - Source:
Returns:
This vector.- Type
- Object
-
normalize() → {Object}
-
Divides a vector by its magnitude to reduce its magnitude to 1. Typically used to retrieve the direction of the vector for later manipulation.
- Source:
Returns:
This vector.- Type
- Object
-
rotate(radians) → {Object}
-
Rotates a vector using a passed angle in radians.
Parameters:
Name Type Description radians
number The angle to rotate in radians. - Source:
Returns:
This vector.- Type
- Object
-
sub(vector) → {Object}
-
Subtracts a vector from this vector.
Parameters:
Name Type Description vector
Object The vector to subtract. - Source:
Returns:
This vector.- Type
- Object