new Vector(x, yopt)
standard 2D Vector
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
x |
number | Object | rat.Vector | |
y |
number |
<optional> |
Methods
(static) cross(a, b) → {number}
Returns the cross product of two vectors
Parameters:
| Name | Type | Description |
|---|---|---|
a |
Object | rat.Vector |
b |
Object | rat.Vector |
Returns:
crossProduct
- Type
- number
(static) dot(a, b) → {number}
Returns the dot product of two vectors
Parameters:
| Name | Type | Description |
|---|---|---|
a |
Object | rat.Vector |
b |
Object | rat.Vector |
Returns:
dotProduct
- Type
- number
add(vec)
Adds another vector to this one
Parameters:
| Name | Type | Description |
|---|---|---|
vec |
Object | rat.Vector |
addScaled(vec, scale)
Multiplies vec by scale and adds it to this vector
Parameters:
| Name | Type | Description |
|---|---|---|
vec |
Object | rat.Vector |
scale |
number |
copy() → {Object}
Makes a copy of this vector and returns it
Returns:
newVec rat.Vector
- Type
- Object
copyFrom(vec)
Sets this vector to be the same as the input vector
Parameters:
| Name | Type | Description |
|---|---|---|
vec |
Object | rat.Vector |
deltaTo(v, destopt) → {Object}
Get a delta vector from this to v
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
v |
Object | rat.Vector | |
dest |
Object |
<optional> |
rat.Vector |
Returns:
delta rat.Vector
- Type
- Object
distanceFrom(v) → {number}
Returns the distance from this vector to another
Parameters:
| Name | Type | Description |
|---|---|---|
v |
Object | rat.Vector |
Returns:
distance
- Type
- number
distanceSqFrom(v) → {number}
Returns the distance squared from this vector to another
Parameters:
| Name | Type | Description |
|---|---|---|
v |
Object | rat.Vector |
Returns:
distance_squared
- Type
- number
length() → {number}
Returns the length of the vector
Returns:
length
- Type
- number
lengthSq() → {number}
Returns the the length of the vector squared
Returns:
length_squared
- Type
- number
limitToRect(r)
Clips vector to fit within a rectangle
Parameters:
| Name | Type | Description |
|---|---|---|
r |
Object | rat.shapes.Rect |
normalize()
Normalizes the vector (Scales to 1)
scale(newScale)
Multiplies the vector by a constant scaler
Parameters:
| Name | Type | Description |
|---|---|---|
newScale |
number |
set(x, yopt)
Sets a vector equal to another vector, or to param x, y values
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
x |
Object | number | rat.Vector | |
y |
number |
<optional> |
setFromAngle(angle)
Sets a vector from an angle (in radians)
NOTE: this assumes a default vector of x=1,y=0
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
number |
setLength(newLength)
Scales the vector to be a specific length
Parameters:
| Name | Type | Description |
|---|---|---|
newLength |
number |
subtract(vec)
Subtracts another vector to this one
Parameters:
| Name | Type | Description |
|---|---|---|
vec |
Object | rat.Vector |
toString() → {string}
Build a string that display this vectors values
Returns:
vector rat.Vector
- Type
- string