vector4
- Last UpdatedSep 17, 2025
- 1 minute read
This topic is about the vector4 data type.
Value syntax
vector4 v4 = {1,1,1,0.5};
Syntax notes
Previous assignment syntax can be used only during initialization. The following code will raise an error.
vector4 v4;
v4 = {1,1,1,0.5};
After a vector4 is declared, it can be populated either by using the implemented API listed below or by assigning it the values from another vector4.
vector4 v4;
vector4 vv4 = {1,1,1,0.5};
v4 = vv4;
Description
Vector4 type is an array of four double values. It is used for properties like RGBA color.
-
The default value is {0,0,0,0}.
-
The vector4 type partially supports arithmetic and comparison operators.
Autocasting
Vector4 type supports automatic conversion for
-
string, if in the correct input format (space separated list of four numbers); otherwise, it will raise an exception.
vector4 v4=”1 2 3 4”; //v4={1,2,3,4};
-
quaternion
quaternion quat={1,2,3,4};
vector4 v4=quat; //v4={1,2,3,4}
Properties
These are the properties for vector4.
|
Property |
Return type |
Parameters |
Description |
|---|---|---|---|
|
x |
double |
|
Used to obtain first value from the vector4. |
|
y |
double |
|
Used to obtain second value from the vector4. |
|
z |
double |
|
Used to obtain third value from the vector4. |
|
w |
double |
|
Used to obtain fourth value from the vector4. |
Methods
This table shows the currently implemented methods.
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
Lerp |
|
vector4 from, vector4 to, double t |
Linearly interpolates between from and to vectors by the interpolant t. |
|
Slerp |
|
vector4 from, vector4 to, double t |
Spherically interpolates between from and to vectors by the interpolant t. |
|
ToString |
string |
Returns a string that represents the current vector4 value. |