Vec2

UMath. Vec2

A 2D Vector Class

Constructor

new Vec2(xopt, yopt)

Source:
Parameters:
Name Type Attributes Default Description
x Number <optional>
0

The x component of the new Vector

y Number <optional>
0

The y component of the new Vector

Methods

add(other) → {UMath.Vec2}

Adds the specified Vector or scalar to this (See UMath.Vec2.add for a static version of this method)

Source:
Parameters:
Name Type Description
other Number | UMath.Vec2 | Vec2Object

The Vector or scalar to add

Returns:
Type:
UMath.Vec2

this

copy() → {UMath.Vec2}

Creates a new Vector that is equal to this

Source:
Returns:
Type:
UMath.Vec2

A copy of this Vector

cross(other) → {Number}

Calculates the Z value of the 3D cross product Vector between this and the specified Vector

Source:
Parameters:
Name Type Description
other UMath.Vec2

The other Vector to calculate the cross product with

Returns:
Type:
Number

The Z value of the 3D cross product Vector

dist(other) → {Number}

Returns the distance between this and the specified Vector (See UMath.Vec2#distSq)

Source:
Parameters:
Name Type Description
other UMath.Vec2 | Vec2Object

The other Vector

Returns:
Type:
Number

The distance between the two vectors

distSq(other) → {Number}

Returns the squared distance between this and the specified Vector (See UMath.Vec2#dist)

Source:
Parameters:
Name Type Description
other UMath.Vec2 | Vec2Object

The other Vector

Returns:
Type:
Number

The squared distance between the two vectors

div(other) → {UMath.Vec2}

Divides this by the specified scalar (See UMath.Vec2.div for a static version of this method)

Source:
Parameters:
Name Type Description
other Number

The scalar to add

Returns:
Type:
UMath.Vec2

this

dot(other) → {Number}

Calculates the dot product between this and the specified Vector

Source:
Parameters:
Name Type Description
other UMath.Vec2

The other Vector to calculate the dot product with

Returns:
Type:
Number

The dot product between this and the specified Vector

mag() → {Number}

Returns the magnitude of the Vector (See UMath.Vec2#magSq)

Source:
Returns:
Type:
Number

The magnitude

magSq() → {Number}

Returns the squared magnitude of the Vector (See UMath.Vec2#mag)

Source:
Returns:
Type:
Number

The squared magnitude

mul(other) → {UMath.Vec2}

Multiplies this by the specified scalar (See UMath.Vec2.mul for a static version of this method)

Source:
Parameters:
Name Type Description
other Number

The scalar to add

Returns:
Type:
UMath.Vec2

this

normalize() → {UMath.Vec2}

Makes the magnitude of this Vector equal to 1 (See UMath.Vec2.normalize for a static version of this method)

Source:
Returns:
Type:
UMath.Vec2

this

rotate(angle) → {UMath.Vec2}

Rotates this by the specified angle (See UMath.Vec2.rotate for a static version of this method)

Source:
Parameters:
Name Type Description
angle Number

The angle to rotate this Vector by

Returns:
Type:
UMath.Vec2

this

sub(other) → {UMath.Vec2}

Subtracts the specified Vector or scalar to this (See UMath.Vec2.sub for a static version of this method)

Source:
Parameters:
Name Type Description
other Number | UMath.Vec2 | Vec2Object

The Vector or scalar to subtract

Returns:
Type:
UMath.Vec2

this

toString() → {String}

Returns this Vector as a String (e.g. "(0, 0)") (See UMath.Vec2.fromString to get a Vector from a String)

Source:
Returns:
Type:
String

This Vector as a String

(static) add(v, other) → {UMath.Vec2}

Returns a new Vector which is the sum of the two specified elements (See UMath.Vec2#add for a non-static version of this method)

Source:
Parameters:
Name Type Description
v UMath.Vec2 | Vec2Object

The Vector to add to

other Number | UMath.Vec2 | Vec2Object

The Vector or scalar to add

Returns:
Type:
UMath.Vec2

The sum of the two elements

(static) div(v, scalar) → {UMath.Vec2}

Returns a new Vector which is the division of the specified Vector by the specified scalar (See UMath.Vec2#div for a non-static version of this method)

Source:
Parameters:
Name Type Description
v UMath.Vec2 | Vec2Object

The Vector to divide

scalar Number

The scalar to divide the Vector by

Returns:
Type:
UMath.Vec2

The division between the specified Vector and the scalar

(static) fromString(str) → {UMath.Vec2}

Returns a new Vector parsed from the specified String (of type "x,y", it removes parenthesis and extra spaces automatically) (See UMath.Vec2#toString to get a String from a Vector)

Source:
Parameters:
Name Type Description
str String

The String to parse

Returns:
Type:
UMath.Vec2

The Vector parsed from the String

(static) mul(v, scalar) → {UMath.Vec2}

Returns a new Vector which is the multiplication of the specified Vector by the specified scalar (See UMath.Vec2#mul for a non-static version of this method)

Source:
Parameters:
Name Type Description
v UMath.Vec2 | Vec2Object

The Vector to multiply

scalar Number

The scalar to multiply the Vector by

Returns:
Type:
UMath.Vec2

The multiplication between the specified Vector and the scalar

(static) normalize(v) → {UMath.Vec2}

Returns a new Vector which is the specified one with a magnitude of 1 (See UMath.Vec2#normalize for a non-static version of this method)

Source:
Parameters:
Name Type Description
v UMath.Vec2 | Vec2Object

The Vector to normalize

Returns:
Type:
UMath.Vec2

The normalized equivalent of the specified Vector

(static) rotate(v, angle) → {UMath.Vec2}

Returns a new Vector equal to the specified Vector rotated by the specified angle (See UMath.Vec2#rotate for a non-static version of this method)

Source:
Parameters:
Name Type Description
v UMath.Vec2 | Vec2Object

The Vector to rotate

angle Number

The angle to rotate the specified Vector by

Returns:
Type:
UMath.Vec2

A new Vector equal to the specified Vector rotated by the specified angle

(static) sub(v, other) → {UMath.Vec2}

Returns a new Vector which is the subtraction of the two specified elements (See UMath.Vec2#sub for a non-static version of this method)

Source:
Parameters:
Name Type Description
v UMath.Vec2 | Vec2Object

The Vector to subtract from

other Number | UMath.Vec2 | Vec2Object

The Vector or scalar to subtract

Returns:
Type:
UMath.Vec2

The subtraction of the two elements