A 2D vector.
groupMath
x: number
The x coordinate
y: number
The y coordinate
set(x: number , y: number ): Vec2
Set the X and Y of this vector
fromAngle(deg: number ): Vec2
Create a new Vec2 from an angle in degrees
fromArray(arr: Array ): Vec2
Create a new Vec2 from an array
An empty vector. (0, 0)
A vector with both components of 1. (1, 1)
A vector signaling to the left. (-1, 0)
A vector signaling to the right. (1, 0)
UP: Vec2
A vector signaling up. (0, -1)
A vector signaling down. (0, 1)
Closest orthogonal direction: LEFT, RIGHT, UP, or DOWN
Clone the vector
copy(v: Vec2 , out: Vec2 ): Vec2
add(args: Vec2Args ): Vec2
Returns the sum with another vector.
add(v: Vec2 , other: Vec2 , out: Vec2 ): Vec2
Calculates the sum of the vectors
paramv- The first term
paramother- The second term
paramout- The vector sum
returnsThe sum of the vectors
addScaled(v: Vec2 , other: Vec2 , s: number , out: Vec2 ): Vec2
addc(v: Vec2 , x: number , y: number , out: Vec2 ): Vec2
Calculates the sum of the vectors
paramv- The first term
paramx- The x of the second term
paramy- The y of the second term
paramout- The vector sum
returnsThe sum of the vectors
sub(args: Vec2Args ): Vec2
Returns the difference with another vector.
sub(v: Vec2 , other: Vec2 , out: Vec2 ): Vec2
Calculates the difference of the vectors
paramv- The first term
paramother- The second term
paramout- The vector difference
returnsThe difference of the vectors
subc(v: Vec2 , x: number , y: number , out: Vec2 ): Vec2
Calculates the difference of the vectors
paramv- The first term
paramx- The x of the second term
paramy- The y of the second term
paramout- The vector difference
returnsThe difference of the vectors
scale(args: Vec2Args ): Vec2
Scale by another vector. or a single number
scale(v: Vec2 , s: number , out: Vec2 ): Vec2
Calculates the scale of the vector
paramv- The vector
params- The x scale
paramout- The y scale
paramunknown- The scaled vector
returnsThe scale of the vector
scalec(v: Vec2 , x: number , y: number , out: Vec2 ): Vec2
Calculates the scale of the vector
paramv- The vector
paramx- The x scale
paramy- The y scale
paramout- The scaled vector
returnsThe scale of the vector
scalev(v: Vec2 , other: Vec2 , out: Vec2 ): Vec2
Calculates the scale of the vector
paramv- The vector
paramother- The scale
paramout- The scaled vector
returnsThe scale of the vector
invScale(args: Vec2Args ): Vec2
Scale by the inverse of another vector. or a single number
dist(args: Vec2Args ): number
Get distance between another vector
dist(v: Vec2 , other: Vec2 ): number
Calculates the distance between the vectors
paramv- The vector
paramother- The other vector
returnsThe between the vectors
sdist(args: Vec2Args ): number
Get squared distance between another vector
sdist(v: Vec2 , other: Vec2 ): number
Calculates the squared distance between the vectors
paramv- The vector
paramother- The other vector
returnsThe distance between the vectors
len(): number
Get length of the vector
sincev3000.0
len(v: Vec2 ): number
Calculates the length of the vector
paramv- The vector
returnsThe length of the vector
slen(): number
Get squared length of the vector
sincev3000.0
slen(v: Vec2 ): number
Calculates the squared length of the vector
paramv- The vector
returnsThe squared length of the vector
Get the unit vector (length of 1).
unit(v: Vec2 , out: Vec2 ): Vec2
Get the perpendicular vector.
normal(v: Vec2 , out: Vec2 ): Vec2
reflect(normal: Vec2 ): Vec2
Get the reflection of a vector with a normal.
sincev3000.0
project(on: Vec2 ): Vec2
Get the projection of a vector onto another vector.
sincev3000.0
reject(on: Vec2 ): Vec2
Get the rejection of a vector onto another vector.
sincev3000.0
rotate(vecOrAngle: Vec2 | number ): Vec2
rotate(v: Vec2 , dir: Vec2 , out: Vec2 ): Vec2
Calculates the rotated vector
paramv- The vector
paramdir- The rotation vector
paramout- The rotated vector
returnsThe rotated vector
rotateByAngle(v: Vec2 , angle: number , out: Vec2 ): Vec2
Calculates the rotated vector
paramv- The vector
paramangle- The angle in radians
paramout- The rotated vector
returnsThe rotated vector
invRotate(vecOrAngle: Vec2 | number ): Vec2
inverseRotate(v: Vec2 , dir: Vec2 , out: Vec2 ): Vec2
Calculates the inverse rotated vector
paramv- The vector
paramdir- The rotation vector
paramout- The rotated vector
returnsThe rotated vector
dot(p2: Vec2 ): number
Get the dot product with another vector.
dot(v: Vec2 , other: Vec2 ): number
Get the dot product between 2 vectors.
sincev3000.0
cross(p2: Vec2 ): number
Get the cross product with another vector.
sincev3000.0
cross(v: Vec2 , other: Vec2 ): number
Get the cross product between 2 vectors.
sincev3000.0
angle(args: Vec2Args ): number
Get the angle of the vector in degrees.
toAngle(v: Vec2 ): number
Calculates the angle represented by the vector in radians
paramv- The vector
returnsAngle represented by the vector in radians
angleBetween(args: Vec2Args ): number
Get the angle between this vector and another vector.
sincev3000.0
angleBetween(v: Vec2 , other: Vec2 ): number
Calculates the angle between the vectors in radians
paramv- First vector
paramother- Second vector
returnsAngle between the vectors in radians
lerp(dest: Vec2 , t: number ): Vec2
Linear interpolate to a destination vector (for positions).
lerp(src: Vec2 , dst: Vec2 , t: number , out: Vec2 ): Vec2
Linear interpolate src and dst by t
paramsrc- First vector
paramdst- Second vector
paramt- Percentage
paramout- The linear interpolation between src and dst by t
returnsThe linear interpolation between src and dst by t
slerp(dest: Vec2 , t: number ): Vec2
Spherical linear interpolate to a destination vector (for rotations).
sincev3000.0
slerp(src: Vec2 , dst: Vec2 , t: number , out: Vec2 ): Vec2
Spherical interpolate src and dst by t
paramsrc- First vector
paramdst- Second vector
paramt- Percentage
paramout- The spherical interpolation between src and dst by t
returnsThe spherical interpolation between src and dst by t
If the vector (x, y) is zero.
sincev3000.0
toFixed(n: number ): Vec2
To n precision floating point.
Multiply by a Mat4.
sincev3000.0
eq(other: Vec2 ): boolean
See if one vector is equal to another.
sincev3000.0
Converts the vector to a Rect with the vector as the origin.
sincev3000.0.
toArray(): Array<number>
Converts the vector to an array.
sincev3001.0
deserialize(data: SerializedVec2 ): Vec2