Vector2

SmilesDrawer. Vector2

A class representing a 2D vector.

Constructor

new Vector2(x, y)

Source:
Properties:
Name Type Description
x Number

The x component of the vector.

y Number

The y component of the vector.

The constructor of the class Vector2.

Parameters:
Name Type Description
x Number

The initial x coordinate value.

y Number

The initial y coordinate value.

Methods

add(vec) → {SmilesDrawer.Vector2}

Source:

Add the x and y coordinate values of a vector to the x and y coordinate values of this vector.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

Another vector.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

angle() → {Number}

Source:

Returns the angle of this vector in relation to the coordinate system.

Returns:

The angle in radians.

Type
Number

clockwise(vec) → {Number}

Source:

Checks whether or not this vector is in a clockwise or counter-clockwise rotational direction compared to another vector in relation to the coordinate system.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

Another vector.

Returns:

Returns -1, 0 or 1 if the vector supplied as an argument is clockwise, neutral or counter-clockwise respectively to this vector in relation to the coordinate system.

Type
Number

clone() → {SmilesDrawer.Vector2}

Source:

Clones this vector and returns the clone.

Returns:

The clone of this vector.

Type
SmilesDrawer.Vector2

distance(vec) → {Number}

Source:

Returns the euclidean distance between this vector and another vector.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

A vector.

Returns:

The euclidean distance between the two vectors.

Type
Number

distanceSq(vec) → {Number}

Source:

Returns the squared euclidean distance between this vector and another vector. When only the relative distances of a set of vectors are needed, this is is less expensive than using distance(vec).

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

Another vector.

Returns:

The squared euclidean distance of the two vectors.

Type
Number

divide(scalar) → {SmilesDrawer.Vector2}

Source:

Divide the x and y coordinate values of this vector by a scalar.

Parameters:
Name Type Description
scalar Number

The scalar.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

getRotateAwayFromAngle(vec, center, angle) → {Number}

Source:

Returns the angle in radians used to rotate this vector away from a given vector.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

The vector this one is rotated away from.

center SmilesDrawer.Vector2

The rotational center.

angle Number

The angle by which to rotate.

Returns:

The angle in radians.

Type
Number

getRotateToAngle(vec, center) → {Number}

Source:

Gets the angles between this vector and another vector around a common center of rotation.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

Another vector.

center SmilesDrawer.Vector2

The center of rotation.

Returns:

The angle between this vector and another vector around a center of rotation in radians.

Type
Number

getRotateTowardsAngle(vec, center, angle) → {Number}

Source:

Returns the angle in radians used to rotate this vector towards a given vector.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

The vector this one is rotated towards to.

center SmilesDrawer.Vector2

The rotational center.

angle Number

The angle by which to rotate.

Returns:

The angle in radians.

Type
Number

invert() → {SmilesDrawer.Vector2}

Source:

Inverts this vector. Same as multiply(-1.0).

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

isInPolygon(polygon) → {Boolean}

Source:

Checks whether a vector lies within a polygon spanned by a set of vectors.

Parameters:
Name Type Description
polygon Array.<SmilesDrawer.Vector2>

An array of vectors spanning the polygon.

Returns:

A boolean indicating whether or not this vector is within a polygon.

Type
Boolean

length() → {Number}

Source:

Returns the length of this vector.

Returns:

The length of this vector.

Type
Number

lengthSq() → {Number}

Source:

Returns the square of the length of this vector.

Returns:

The square of the length of this vector.

Type
Number

multiply(v) → {SmilesDrawer.Vector2}

Source:

Multiply the x and y coordinate values of this vector by the values of another vector.

Parameters:
Name Type Description
v SmilesDrawer.Vector2

A vector.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

multiplyScalar(scalar) → {SmilesDrawer.Vector2}

Source:

Multiply the x and y coordinate values of this vector by a scalar.

Parameters:
Name Type Description
scalar Number

The scalar.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

normalize() → {SmilesDrawer.Vector2}

Source:

Normalizes this vector.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

normalized() → {SmilesDrawer.Vector2}

Source:

Returns a normalized copy of this vector.

Returns:

A normalized copy of this vector.

Type
SmilesDrawer.Vector2

rotate(angle) → {SmilesDrawer.Vector2}

Source:

Rotates this vector by a given number of radians around the origin of the coordinate system.

Parameters:
Name Type Description
angle Number

The angle in radians to rotate the vector.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

rotateAround(angle, vec) → {SmilesDrawer.Vector2}

Source:

Rotates this vector around another vector.

Parameters:
Name Type Description
angle Number

The angle in radians to rotate the vector.

vec SmilesDrawer.Vector2

The vector which is used as the rotational center.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

rotateAwayFrom(vec, center, angle)

Source:

Rotates the vector away from a specified vector around a center.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

The vector this one is rotated away from.

center SmilesDrawer.Vector2

The rotational center.

angle Number

The angle by which to rotate.

rotateTo(vec, center, offsetAngleopt) → {SmilesDrawer.Vector2}

Source:

Rotate a vector around a given center to the same angle as another vector (so that the two vectors and the center are in a line, with both vectors on one side of the center), keeps the distance from this vector to the center.

Parameters:
Name Type Attributes Default Description
vec SmilesDrawer.Vector2

The vector to rotate this vector to.

center SmilesDrawer.Vector2

The rotational center.

offsetAngle Number <optional>
0.0

An additional amount of radians to rotate the vector.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

sameSideAs(vecA, vecB, vecC) → {Boolean}

Source:

Checks whether or not this vector is on the same side of a line spanned by two vectors as another vector.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector spanning the line.

vecB SmilesDrawer.Vector2

A vector spanning the line.

vecC SmilesDrawer.Vector2

A vector to check whether or not it is on the same side as this vector.

Returns:

Returns a boolean indicating whether or not this vector is on the same side as another vector.

Type
Boolean

subtract(vec) → {SmilesDrawer.Vector2}

Source:

Subtract the x and y coordinate values of a vector from the x and y coordinate values of this vector.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

Another vector.

Returns:

Returns itself.

Type
SmilesDrawer.Vector2

toString() → {String}

Source:

Returns a string representation of this vector.

Returns:

A string representation of this vector.

Type
String

whichSide(vecA, vecB) → {Number}

Source:

Calculates which side of a line spanned by two vectors this vector is.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector.

vecB SmilesDrawer.Vector2

A vector.

Returns:

A number indicating the side of this vector, given a line spanned by two other vectors.

Type
Number

(static) add(vecA, vecB) → {SmilesDrawer.Vector2}

Source:

Adds two vectors and returns the result as a new vector.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A summand.

vecB SmilesDrawer.Vector2

A summand.

Returns:

Returns the sum of two vectors.

Type
SmilesDrawer.Vector2

(static) angle(vecA, vecB) → {Number}

Source:

Returns the angle between two vectors.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector.

vecB SmilesDrawer.Vector2

A vector.

Returns:

The angle between two vectors in radians.

Type
Number

(static) averageDirection(vecs) → {SmilesDrawer.Vector2}

Source:

Returns the average vector (normalized) of the input vectors.

Parameters:
Name Type Description
vecs Array()

An array containing vectors.

Returns:

The resulting vector (normalized).

Type
SmilesDrawer.Vector2

(static) divide(vecA, vecB) → {SmilesDrawer.Vector2}

Source:

Divides a vector by another vector and returns the result as new vector.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

The dividend.

vecB SmilesDrawer.Vector2

The divisor.

Returns:

The fraction of the two vectors.

Type
SmilesDrawer.Vector2

(static) dot(vecA, vecB) → {Number}

Source:

Returns the dot product of two vectors.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector.

vecB SmilesDrawer.Vector2

A vector.

Returns:

The dot product of two vectors.

Type
Number

(static) midpoint(vecA, vecB) → {SmilesDrawer.Vector2}

Source:

Returns the midpoint of a line spanned by two vectors.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector spanning the line.

vecB SmilesDrawer.Vector2

A vector spanning the line.

Returns:

The midpoint of the line spanned by two vectors.

Type
SmilesDrawer.Vector2

(static) multiply(vecA, vecB) → {SmilesDrawer.Vector2}

Source:

Multiplies two vectors (value by value) and returns the result.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector.

vecB SmilesDrawer.Vector2

A vector.

Returns:

Returns the product of two vectors.

Type
SmilesDrawer.Vector2

(static) multiplyScalar(vec, scalar) → {SmilesDrawer.Vector2}

Source:

Multiplies two vectors (value by value) and returns the result.

Parameters:
Name Type Description
vec SmilesDrawer.Vector2

A vector.

scalar Number

A scalar.

Returns:

Returns the product of two vectors.

Type
SmilesDrawer.Vector2

(static) normals(vecA, vecB) → {Array.<SmilesDrawer.Vector2>}

Source:

Returns the normals of a line spanned by two vectors.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector spanning the line.

vecB SmilesDrawer.Vector2

A vector spanning the line.

Returns:

An array containing the two normals, each represented by a vector.

Type
Array.<SmilesDrawer.Vector2>

(static) scalarProjection(vecA, vecB) → {Number}

Source:

Returns the scalar projection of a vector on another vector.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

The vector to be projected.

vecB SmilesDrawer.Vector2

The vector to be projection upon.

Returns:

The scalar component.

Type
Number

(static) subtract(vecA, vecB) → {SmilesDrawer.Vector2}

Source:

Subtracts one vector from another and returns the result as a new vector.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

The minuend.

vecB SmilesDrawer.Vector2

The subtrahend.

Returns:

Returns the difference of two vectors.

Type
SmilesDrawer.Vector2

(static) threePointangle(vecA, vecB, vecC) → {Number}

Source:

Returns the angle between two vectors based on a third vector in between.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector.

vecB SmilesDrawer.Vector2

A vector.

vecC SmilesDrawer.Vector2

A vector.

Returns:

The angle in radians.

Type
Number

(static) units(vecA, vecB) → {Array.<SmilesDrawer.Vector2>}

Source:

Returns the unit (normalized normal) vectors of a line spanned by two vectors.

Parameters:
Name Type Description
vecA SmilesDrawer.Vector2

A vector spanning the line.

vecB SmilesDrawer.Vector2

A vector spanning the line.

Returns:

An array containing the two unit vectors.

Type
Array.<SmilesDrawer.Vector2>