Class: Vec2

algeobra~Vec2()

Grouping of basic 2D vector operations

Constructor

new Vec2()

Source:

Methods

(static) add(a, b) → {Object}

Adds two vector like objects
Parameters:
Name Type Description
a Object
b Object
Source:
Returns:
a+b
Type
Object

(static) cwiseDiv(a, b) → {Object}

Divides two vector like objects component-wise
Parameters:
Name Type Description
a Object
b Object
Source:
Returns:
Component-wise division of a and b
Type
Object

(static) cwiseMult(a, b) → {Object}

Multiplies two vector like objects component-wise
Parameters:
Name Type Description
a Object
b Object
Source:
Returns:
Component-wise multiplication of a and b
Type
Object

(static) dot(a, b) → {Number}

Computes the dot product of two vector like objects
Parameters:
Name Type Description
a Object
b Object
Source:
Returns:
The dot product
Type
Number

(static) len(a) → {Number}

Computes the length of a vector like objects
Parameters:
Name Type Description
a Object
Source:
Returns:
The length
Type
Number

(static) len2(a) → {Number}

Computes the squared length of a vector like objects
Parameters:
Name Type Description
a Object
Source:
Returns:
The squared length
Type
Number

(static) lerp(a, b, t) → {Object}

Computes the linear interpolation (1-t)*a + t*b
Parameters:
Name Type Description
a Object
b Object
t Number
Source:
Returns:
The linearly interpolated vector
Type
Object

(static) new(x, y) → {Object}

Create an object that can be treated as a 2D vector
Parameters:
Name Type Default Description
x Number 0
y Number 0
Source:
Returns:
A 2D vector
Type
Object

(static) normal2D(v) → {Object}

Computes the normal [-y,x] for the given vector [x,y]
Parameters:
Name Type Description
v Object The input vector
Source:
Returns:
The normal
Type
Object

(static) normalize(v) → {Object}

Creates a new normalized vector
Parameters:
Name Type Description
v Object The vector to normalized
Source:
Returns:
The normalized vector
Type
Object

(static) normalizeIfNotZero(v, eps) → {Object}

Creates a new normalized vector, if the vector is not zero, otherwise does not change the values
Parameters:
Name Type Default Description
v Object The vector to normalized
eps Number 1e-10 [1E-10] The epsilon to check whether a vector is approximately zero or not
Source:
Returns:
The normalized vector
Type
Object

(static) polar(r, alpha) → {Object}

Creates a 2D cartesian vector from its polar coordinates
Parameters:
Name Type Description
r Number The radius
alpha Number The angle
Source:
Returns:
The vector
Type
Object

(static) rotate(v, alpha, ca, sa) → {Object}

Rotates a vector by a given angle
Parameters:
Name Type Description
v Object The vector to rotate
alpha Number The angle around which to rotate
ca Number [Math.cos(alpha)] The cosine of alpha can be provided. If many points are rotated, this saves computing the cosine multiple times
sa Number [Math.sin(alpha)] he sine of alpha can be provided. If many points are rotated, this saves computing the sine multiple times
Source:
Returns:
The rotated vector
Type
Object

(static) scale(a, b) → {Object}

Adds a vector like object by a scalar
Parameters:
Name Type Description
a Object
b Number
Source:
Returns:
a*v
Type
Object

(static) sub(a, b) → {Object}

Subtracts two vector like objects
Parameters:
Name Type Description
a Object
b Object
Source:
Returns:
a+b
Type
Object

(static) vec2(x, y) → {Object}

Create an object that can be treated as a 2D vector
Parameters:
Name Type Default Description
x Number 0
y Number 0
Source:
Returns:
A 2D vector
Type
Object