Home Reference Source Test Repository
public class | source

Vector2D

Class for representing 2D vectors.

Test:

Constructor Summary

Public Constructor
public

Constructs a Vector2D object.

Member Summary

Public Members
public get

Getter for vector length.

public

x: *

public

y: *

Method Summary

Public Methods
public

Finds the result of addition with another vector.

public

Finds the "cross product" between this vector and another vector.

public

Finds the angle between two vectors (in degrees).

public

Finds the dot product between this vector and another vector.

public

Checks if this vector and another vector are equal.

public

Finds the vector projection of this vector onto another vector.

public

Finds the vector resulting from a rotation in degrees.

public

Finds the vector resulting from a rotation in radians.

public

Finds the vector resulting from multiplication by a scalar.

public

Finds the result of subtracting another vector.

Public Constructors

public constructor(x: number, y: number) source

Constructs a Vector2D object.

Params:

NameTypeAttributeDescription
x number

x-component of the vector.

y number

y-component of the vector.

Test:

Public Members

public get length: number: * source

Getter for vector length.

Return:

number

The length of the vector.

Test:

public x: * source

public y: * source

Public Methods

public add(vec: Vector2D): Vector2D source

Finds the result of addition with another vector.

Params:

NameTypeAttributeDescription
vec Vector2D

The vector to add.

Return:

Vector2D

The result of vector addition.

Test:

public cross(vec: Vector2D): number source

Finds the "cross product" between this vector and another vector.

Params:

NameTypeAttributeDescription
vec Vector2D

Vector to find the cross product with.

Return:

number

The value of the cross product. Zero means the vectors are parallel.

Test:

public degreesTo(vec: Vector2D): number source

Finds the angle between two vectors (in degrees).

Params:

NameTypeAttributeDescription
vec Vector2D

Vector to find the angle to.

Return:

number

Angle between the vectors in degrees.

Test:

public dot(vec: Vector2D): number source

Finds the dot product between this vector and another vector.

Params:

NameTypeAttributeDescription
vec Vector2D

Vector to find a dot product with.

Return:

number

The value of the dot product.

Test:

public equals(vec: Vector2D): boolean source

Checks if this vector and another vector are equal. Returns true if the x- and y-components are equal.

Params:

NameTypeAttributeDescription
vec Vector2D

Vector to compare with.

Return:

boolean

Whether or not the vectors are equivalent.

Test:

public projectOnto(vec: Vector2D): Vector2D source

Finds the vector projection of this vector onto another vector.

Params:

NameTypeAttributeDescription
vec Vector2D

Vector to project onto.

Return:

Vector2D

Vector resulting from the vector projection.

Test:

public rotateDegrees(deg: number): Vector2D source

Finds the vector resulting from a rotation in degrees.

Params:

NameTypeAttributeDescription
deg number

Angle (in degrees) to rotate.

Return:

Vector2D

Vector resulting from the rotation.

Test:

public rotateRadians(rad: number): Vector2D source

Finds the vector resulting from a rotation in radians.

Params:

NameTypeAttributeDescription
rad number

Angle (in radians) to rotate.

Return:

Vector2D

Vector resulting from the rotation.

Test:

public scale(n: number): Vector2D source

Finds the vector resulting from multiplication by a scalar.

Params:

NameTypeAttributeDescription
n number

The scalar to multiply by.

Return:

Vector2D

Vector resulting from the scale.

Test:

public sub(vec: Vector2D): Vector2D source

Finds the result of subtracting another vector.

Params:

NameTypeAttributeDescription
vec Vector2D

The vector to subtract.

Return:

Vector2D

The result of vector subtraction.

Test: