Class
: A 2D vector.
: number The x coordinate
: number The y coordinate
(x: number, y: number)
=> Vec2 Set the X and Y of this vector
static (deg: number)
=> Vec2 Create a new Vec2 from an angle in degrees
static (arr: Array<number>)
=> Vec2 Create a new Vec2 from an array
static : Vec2 An empty vector. (0, 0)
static : Vec2 A vector with both components of 1. (1, 1)
static : Vec2 A vector signaling to the left. (-1, 0)
static : Vec2 A vector signaling to the right. (1, 0)
static : Vec2 A vector signaling up. (0, -1)
static : Vec2 A vector signaling down. (0, 1)
()
=> Vec2 Closest orthogonal direction: LEFT, RIGHT, UP, or DOWN
()
=> Vec2 Clone the vector
static (v: Vec2, out: Vec2)
=> Vec2 (args: Vec2Args)
=> Vec2 Returns the sum with another vector.
static (v: Vec2, other: Vec2, out: Vec2)
=> Vec2 Calculates the sum of the vectors
param v- The first term
param other- The second term
param out- The vector sum
returns The sum of the vectors
static (v: Vec2, other: Vec2, s: number, out: Vec2)
=> Vec2 static (v: Vec2, x: number, y: number, out: Vec2)
=> Vec2 Calculates the sum of the vectors
param v- The first term
param x- The x of the second term
param y- The y of the second term
param out- The vector sum
returns The sum of the vectors
(args: Vec2Args)
=> Vec2 Returns the difference with another vector.
static (v: Vec2, other: Vec2, out: Vec2)
=> Vec2 Calculates the difference of the vectors
param v- The first term
param other- The second term
param out- The vector difference
returns The difference of the vectors
static (v: Vec2, x: number, y: number, out: Vec2)
=> Vec2 Calculates the difference of the vectors
param v- The first term
param x- The x of the second term
param y- The y of the second term
param out- The vector difference
returns The difference of the vectors
(args: Vec2Args)
=> Vec2 Scale by another vector. or a single number
static (v: Vec2, s: number, out: Vec2)
=> Vec2 Calculates the scale of the vector
param v- The vector
param s- The x scale
param out- The y scale
param unknown- The scaled vector
returns The scale of the vector
static (v: Vec2, x: number, y: number, out: Vec2)
=> Vec2 Calculates the scale of the vector
param v- The vector
param x- The x scale
param y- The y scale
param out- The scaled vector
returns The scale of the vector
static (v: Vec2, other: Vec2, out: Vec2)
=> Vec2 Calculates the scale of the vector
param v- The vector
param other- The scale
param out- The scaled vector
returns The scale of the vector
(args: Vec2Args)
=> Vec2 Scale by the inverse of another vector. or a single number
(args: Vec2Args)
=> number Get distance between another vector
static (v: Vec2, other: Vec2)
=> number Calculates the distance between the vectors
param v- The vector
param other- The other vector
returns The between the vectors
(args: Vec2Args)
=> number Get squared distance between another vector
static (v: Vec2, other: Vec2)
=> number Calculates the squared distance between the vectors
param v- The vector
param other- The other vector
returns The distance between the vectors
()
=> number Get length of the vector
static (v: Vec2)
=> number Calculates the length of the vector
param v- The vector
returns The length of the vector
()
=> number Get squared length of the vector
static (v: Vec2)
=> number Calculates the squared length of the vector
param v- The vector
returns The squared length of the vector
()
=> Vec2 Get the unit vector (length of 1).
static (v: Vec2, out: Vec2)
=> Vec2 ()
=> Vec2 Get the perpendicular vector.
static (v: Vec2, out: Vec2)
=> Vec2 (normal: Vec2)
=> Vec2 Get the reflection of a vector with a normal.
(on: Vec2)
=> Vec2 Get the projection of a vector onto another vector.
(on: Vec2)
=> Vec2 Get the rejection of a vector onto another vector.
(vecOrAngle: Vec2 | number)
=> Vec2 static (v: Vec2, dir: Vec2, out: Vec2)
=> Vec2 Calculates the rotated vector
param v- The vector
param dir- The rotation vector
param out- The rotated vector
returns The rotated vector
static (v: Vec2, angle: number, out: Vec2)
=> Vec2 Calculates the rotated vector
param v- The vector
param angle- The angle in radians
param out- The rotated vector
returns The rotated vector
(vecOrAngle: Vec2 | number)
=> Vec2 static (v: Vec2, dir: Vec2, out: Vec2)
=> Vec2 Calculates the inverse rotated vector
param v- The vector
param dir- The rotation vector
param out- The rotated vector
returns The rotated vector
(p2: Vec2)
=> number Get the dot product with another vector.
static (v: Vec2, other: Vec2)
=> number Get the dot product between 2 vectors.
(p2: Vec2)
=> number Get the cross product with another vector.
static (v: Vec2, other: Vec2)
=> number Get the cross product between 2 vectors.
(args: Vec2Args)
=> number Get the angle of the vector in degrees.
static (v: Vec2)
=> number Calculates the angle represented by the vector in radians
param v- The vector
returns Angle represented by the vector in radians
(args: Vec2Args)
=> number Get the angle between this vector and another vector.
static (v: Vec2, other: Vec2)
=> number Calculates the angle between the vectors in radians
param v- First vector
param other- Second vector
returns Angle between the vectors in radians
(dest: Vec2, t: number)
=> Vec2 Linear interpolate to a destination vector (for positions).
static (src: Vec2, dst: Vec2, t: number, out: Vec2)
=> Vec2 Linear interpolate src and dst by t
param src- First vector
param dst- Second vector
param t- Percentage
param out- The linear interpolation between src and dst by t
returns The linear interpolation between src and dst by t
(dest: Vec2, t: number)
=> Vec2 Spherical linear interpolate to a destination vector (for rotations).
static (src: Vec2, dst: Vec2, t: number, out: Vec2)
=> Vec2 Spherical interpolate src and dst by t
param src- First vector
param dst- Second vector
param t- Percentage
param out- The spherical interpolation between src and dst by t
returns The spherical interpolation between src and dst by t
()
=> boolean If the vector (x, y) is zero.
(n: number)
=> Vec2 To n precision floating point.
(m: Mat4)
=> Vec2 Multiply by a Mat4.
(other: Vec2)
=> boolean See if one vector is equal to another.
()
=> Rect Converts the vector to a Rect with the vector as the origin.
()
=> Array<number> Converts the vector to an array.
static (data: SerializedVec2)
=> Vec2