vector2
- Last UpdatedSep 17, 2025
- 1 minute read
This topic is about the vector2 data type.
Value syntax
vector2 v2 = {1.3,-2};
Syntax notes
Previous assignment syntax can be used only during initialization. The following code will raise an error.
vector2 v2;
v2 = {1.3,-2};
After a vector2 is declared, it can be populated either by using the implemented API listed below or by assigning it the values from another vector2.
vector2 v2;
vector2 vv2 = {1.3,-2};
v2 = vv2;
Description
Vector2 type is an array of two double values. It is used for properties such as 2D positions.
-
The default value is {0,0}.
-
Vector2 type partially supports arithmetic and comparison operators.
Autocasting
Vector2 type supports automatic conversion for
-
string, if in the correct input format (space separated list of two numbers); otherwise, it will raise an exception.
vector2 v2=”1 2”; //v2={1,2};
Properties
These are the properties for vector2.
|
Property |
Return type |
Parameters |
Description |
|---|---|---|---|
|
x |
double |
|
Used to obtain first value from the vector2. |
|
y |
double |
|
Used to obtain second value from the vector2. |
Methods
This table shows the currently implemented methods.
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
Length |
double |
|
Returns the length of the vector2. |
|
Length2 |
double |
|
Returns the squared length of the vector2. |
|
Lerp |
|
vector2 from, vector2 to, double t |
Linearly interpolates between from and to vectors by the interpolant t. |
|
Normalize |
|
|
Overwrites the vector2 with the normalized vector2. |
|
Slerp |
|
vector2 from, vector2 to, double t |
Spherically interpolates between from and to vectors by the interpolant t. |
|
ToString |
string |
Returns a string that represents the current vector2 value. |