Class: Vector

rat. Vector

new Vector(x, yopt)

standard 2D Vector
Parameters:
Name Type Attributes Description
x number | Object rat.Vector
y number <optional>
Source:

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
Source:
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
Source:
Returns:
dotProduct
Type
number

add(vec)

Adds another vector to this one
Parameters:
Name Type Description
vec Object rat.Vector
Source:

addScaled(vec, scale)

Multiplies vec by scale and adds it to this vector
Parameters:
Name Type Description
vec Object rat.Vector
scale number
Source:

copy() → {Object}

Makes a copy of this vector and returns it
Source:
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
Source:

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
Source:
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
Source:
Returns:
distance
Type
number

distanceSqFrom(v) → {number}

Returns the distance squared from this vector to another
Parameters:
Name Type Description
v Object rat.Vector
Source:
Returns:
distance_squared
Type
number

length() → {number}

Returns the length of the vector
Source:
Returns:
length
Type
number

lengthSq() → {number}

Returns the the length of the vector squared
Source:
Returns:
length_squared
Type
number

limitToRect(r)

Clips vector to fit within a rectangle
Parameters:
Name Type Description
r Object rat.shapes.Rect
Source:

normalize()

Normalizes the vector (Scales to 1)
Source:

scale(newScale)

Multiplies the vector by a constant scaler
Parameters:
Name Type Description
newScale number
Source:

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>
Source:

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
Source:

setLength(newLength)

Scales the vector to be a specific length
Parameters:
Name Type Description
newLength number
Source:

subtract(vec)

Subtracts another vector to this one
Parameters:
Name Type Description
vec Object rat.Vector
Source:

toString() → {string}

Build a string that display this vectors values
Source:
Returns:
vector rat.Vector
Type
string