Constructor
new Vector2D(x, y)
Instantiate a new Vector2D.
| Name | Type | Description |
|---|---|---|
x | Number | |
y | Number |
- Source
Methods
add(v) → {Vector2D}
returns a new added vector denoted by this + v.
| Name | Type | Description |
|---|---|---|
v | Vector2D | vector to be added |
- Source
- Type:
- Vector2D
addTo(v)
adds a vector to the current vector (this = this + v).
| Name | Type | Description |
|---|---|---|
v | Vector2D |
- Source
angleBetween(v, type) → {number}
return the angle between this and v.
| Name | Type | Default | Description |
|---|---|---|---|
v | Vector2D | ||
type | boolean | true | default set to |
- Source
- Type:
- number
cross(v) → {Number}
returns the "cross-product" of two vectors (this and v). Since these are 2D vectors, this is the z-coordinate of the 3D counter parts of these 2D vectors. It returns a scalar.
| Name | Type | Description |
|---|---|---|
v | Vector2D |
- Source
- Type:
- Number
dot(v) → {Number}
returns the dot product of two vectors (this and v).
| Name | Type | Description |
|---|---|---|
v | Vector2D |
- Source
- Type:
- Number
mag() → {Number}
returns the magnitude of the vector.
- Source
- Type:
- Number
magSqr() → {Number}
returns the magnitude squared of the vector.
- Source
- Type:
- Number
mult(a) → {Vector2D}
returns a new scalar-multiplied vector denoted by this * a.
| Name | Type | Description |
|---|---|---|
a | Number | scalar multiple |
- Source
- Type:
- Vector2D
multTo(a)
multiplies a scalar to the current vector (this = this * a).
| Name | Type | Description |
|---|---|---|
a | Number |
- Source
normalize() → {Vector2D}
returns a new normalized Vector2D.
- Source
- Type:
- Vector2D
normalizeTo()
normalizes the this Vector2D.
- Source
reflect(normal)
Performs the mirror reflection for this about a normal vector.
| Name | Type | Description |
|---|---|---|
normal | Vector2D |
- Source
Vector2D
reflectTo(normal)
Performs the mirror reflection for this about a normal vector. (modifies self)
| Name | Type | Description |
|---|---|---|
normal | Vector2D |
- Source
sub(v) → {Vector2D}
returns a new subtracted vector denoted by this - v.
| Name | Type | Description |
|---|---|---|
v | Vector2D | vector to be added |
- Source
- Type:
- Vector2D
subTo(v)
subtracts a vector to the current vector (this = this - v).
| Name | Type | Description |
|---|---|---|
v | Vector2D |
- Source