Vector2d

class Vector2d

a generic 2D Vector Object

Constructor


new Vector2d(x: number, y: number) → {}
Parameters:
Name Type Attributes Default Description
x number

<optional>

0

x value of the vector

y number

<optional>

0

y value of the vector

Public Properties


x vector2.js:23
x: number

number

x value of the vector

y vector2.js:28
y: number

number

y value of the vector

Public Methods


abs vector2.js:140
abs() → {Vector2d}

Update this vector values to absolute values

Returns:
Type Description
Vector2d

Reference to this object for method chaining

add vector2.js:78
add(v: Vector2d) → {Vector2d}

Add the passed vector to this vector

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

angle vector2.js:381
angle(v: Vector2d) → {number}

return the angle between this vector and the passed one

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
number

angle in radians

ceil vector2.js:202
ceil() → {Vector2d}

Ceil the vector values

Returns:
Type Description
Vector2d

new me.Vector2d

ceilSelf vector2.js:210
ceilSelf() → {Vector2d}

Ceil this vector values

Returns:
Type Description
Vector2d

Reference to this object for method chaining

clamp vector2.js:148
clamp(low: number, high: number) → {Vector2d}

Clamp the vector value within the specified value range

Parameters:
Name Type Description
low number
high number
Returns:
Type Description
Vector2d

new me.Vector2d

clampSelf vector2.js:158
clampSelf(low: number, high: number) → {Vector2d}

Clamp this vector value within the specified value range

Parameters:
Name Type Description
low number
high number
Returns:
Type Description
Vector2d

Reference to this object for method chaining

clone vector2.js:409
clone() → {Vector2d}

return a clone copy of this vector

Returns:
Type Description
Vector2d

new me.Vector2d

copy vector2.js:234
copy(v: Vector2d) → {Vector2d}

Copy the x,y values of the passed vector to this one

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

cross vector2.js:313
cross(v: Vector2d) → {number}

return the cross product of this vector and the passed one

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
number

The cross product.

distance vector2.js:371
distance(v: Vector2d) → {number}

return the distance between this vector and the passed one

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
number
div vector2.js:131
div(n: number) → {Vector2d}

Divide this vector values by the passed value

Parameters:
Name Type Description
n number

the value to divide the vector by

Returns:
Type Description
Vector2d

Reference to this object for method chaining

dot vector2.js:304
dot(v: Vector2d) → {number}

return the dot product of this vector and the passed one

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
number

The dot product.

equals vector2.js:243
equals(x: number | Vector2d | ObservableVector2d, y: number) → {boolean}

return true if this vector is equal to the given values or vector

Parameters:
Name Type Attributes Description
x number | Vector2d | ObservableVector2d
y number

<optional>

Returns:
Type Description
boolean
floor vector2.js:186
floor() → {Vector2d}

Floor the vector values

Returns:
Type Description
Vector2d

new me.Vector2d

floorSelf vector2.js:194
floorSelf() → {Vector2d}

Floor this vector values

Returns:
Type Description
Vector2d

Reference to this object for method chaining

length vector2.js:330
length() → {number}

return the length (magnitude) of this vector

Returns:
Type Description
number

the length of this vector

length2 vector2.js:322
length2() → {number}

return the square length of this vector

Returns:
Type Description
number

The length^2 of this vector.

lerp vector2.js:338
lerp(v: Vector2d, alpha: number) → {Vector2d}

Linearly interpolate between this vector and the given one.

Parameters:
Name Type Description
v Vector2d
alpha number

distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).

Returns:
Type Description
Vector2d

Reference to this object for method chaining

maxV vector2.js:177
maxV(v: Vector2d) → {Vector2d}

Update this vector with the maximum value between this and the passed vector

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

minV vector2.js:168
minV(v: Vector2d) → {Vector2d}

Update this vector with the minimum value between this and the passed vector

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

moveTowards vector2.js:350
moveTowards(target: Vector2d, step: number) → {Vector2d}

interpolate the position of this vector towards the given one by the given maximum step.

Parameters:
Name Type Description
target Vector2d
step number

the maximum step per iteration (Negative values will push the vector away from the target)

Returns:
Type Description
Vector2d

Reference to this object for method chaining

negate vector2.js:218
negate() → {Vector2d}

Negate the vector values

Returns:
Type Description
Vector2d

new me.Vector2d

negateSelf vector2.js:226
negateSelf() → {Vector2d}

Negate this vector values

Returns:
Type Description
Vector2d

Reference to this object for method chaining

normalize vector2.js:263
normalize() → {Vector2d}

normalize this vector (scale the vector so that its magnitude is 1)

Returns:
Type Description
Vector2d

Reference to this object for method chaining

perp vector2.js:271
perp() → {Vector2d}

change this vector to be perpendicular to what it was before.
(Effectively rotates it 90 degrees in a clockwise direction)

Returns:
Type Description
Vector2d

Reference to this object for method chaining

project vector2.js:390
project(v: Vector2d) → {Vector2d}

project this vector on to another vector.

Parameters:
Name Type Description
v Vector2d

The vector to project onto.

Returns:
Type Description
Vector2d

Reference to this object for method chaining

projectN vector2.js:399
projectN(v: Vector2d) → {Vector2d}

Project this vector onto a vector of unit length.
This is slightly more efficient than project when dealing with unit vectors.

Parameters:
Name Type Description
v Vector2d

The unit vector to project onto.

Returns:
Type Description
Vector2d

Reference to this object for method chaining

rotate vector2.js:280
rotate(angle: number, v: Vector2d | ObservableVector2d) → {Vector2d}

Rotate this vector (counter-clockwise) by the specified angle (in radians).

Parameters:
Name Type Attributes Description
angle number

The angle to rotate (in radians)

v Vector2d | ObservableVector2d

<optional>

an optional point to rotate around

Returns:
Type Description
Vector2d

Reference to this object for method chaining

scale vector2.js:96
scale(x: number, y: number) → {Vector2d}

Multiply this vector values by the given scalar

Parameters:
Name Type Attributes Default Description
x number
y number

<optional>

x
Returns:
Type Description
Vector2d

Reference to this object for method chaining

scaleV vector2.js:122
scaleV(v: Vector2d) → {Vector2d}

Multiply this vector values by the passed vector

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

set vector2.js:46
set(x: number, y: number) → {Vector2d}

set the Vector x and y properties to the given values

Parameters:
Name Type Description
x number
y number
Returns:
Type Description
Vector2d

Reference to this object for method chaining

setV vector2.js:69
setV(v: Vector2d) → {Vector2d}

set the Vector x and y properties using the passed vector

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

setZero vector2.js:61
setZero() → {Vector2d}

set the Vector x and y properties to 0

Returns:
Type Description
Vector2d

Reference to this object for method chaining

sub vector2.js:87
sub(v: Vector2d) → {Vector2d}

Substract the passed vector to this vector

Parameters:
Name Type Description
v Vector2d
Returns:
Type Description
Vector2d

Reference to this object for method chaining

to2d vector2.js:114
to2d() → {Vector2d}

Convert this vector into 2d coordinate space

Returns:
Type Description
Vector2d

Reference to this object for method chaining

toIso vector2.js:106
toIso() → {Vector2d}

Convert this vector into isometric coordinate space

Returns:
Type Description
Vector2d

Reference to this object for method chaining

toString vector2.js:417
toString() → {string}

convert the object to a string representation

Returns:
Type Description
string

Powered by webdoc!