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