Vector2
Overview
Description
The Vector2
class represents a mathematical 2D vector with x and y components. It is commonly used in game development or graphical applications for 2D position, direction, and mathematical operations.
Properties
X
number
The x-coordinate of the vector.
Code Samples
Y
number
The y-coordinate of the vector.
Code Samples
zero
Vector2
A vector whose x and y components are both zero. Typically used to represent the origin or a null vector.
Code Samples
one
Vector2
A vector whose x and y components are both set to 1.
Code Samples
xAxis
Vector2
A unit vector pointing in the x-axis direction (1, 0).
Code Samples
yAxis
Vector2
A unit vector pointing in the y-axis direction (0, 1).
Code Samples
Constructors
new
Creates a new instance of the Vector2
class with given x and y components.
Parameters
number
x
The x-coordinate of the vector.
number
y
The y-coordinate of the vector.
Return
Vector2
A new vector with the specified x and y coordinates.
Code Samples
Methods
Add
Adds two vectors and returns the result.
Parameters
Vector2
other
The vector to add.
Return
Vector2
The result of vector addition.
Code Samples
Subtract
Subtracts another vector from this vector.
Parameters
Vector2
other
The vector to subtract.
Return
Vector2
The result of vector subtraction.
Code Samples
Multiply
Multiplies the components of the vector by a scalar value.
Parameters
number
scalar
The scalar value to multiply with.
Return
Vector2
The scaled vector.
Code Samples
Magnitude
Calculates the magnitude (length) of the vector.
Return
number
The magnitude of the vector.
Code Samples
Normalize
Normalizes the vector (makes it a unit vector).
Return
Vector2
The normalized vector.
Code Samples
Last updated