Vector4
A four-component vector.
Constructors
Constructor Name | Return Type | Description | Tags |
---|---|---|---|
Vector4.New([number x, number y, number z, number w]) |
Vector4 |
Constructs a Vector4 with the given x , y , z , w values, defaults to (0, 0, 0, 0). |
None |
Vector4.New(number v) |
Vector4 |
Constructs a Vector4 with x , y , z , w values all set to the given value. |
None |
Vector4.New(Vector3 xyz, number w) |
Vector4 |
Constructs a Vector4 with x , y , z values from the given Vector3 and the given w value. |
None |
Vector4.New(Vector4 v) |
Vector4 |
Constructs a Vector4 with x , y , z , w values from the given Vector4. |
None |
Vector4.New(Vector2 xy, Vector2 zw) |
Vector4 |
Constructs a Vector4 with x , y values from the first Vector2 and z , w values from the second Vector2. |
None |
Vector4.New(Color v) |
Vector4 |
Constructs a Vector4 with x , y , z , w values mapped from the given Color's r , g , b , a values. |
None |
Constants
Properties
Property Name | Return Type | Description | Tags |
---|---|---|---|
x |
number |
The x component of the Vector4. |
Read-Write |
y |
number |
The y component of the Vector4. |
Read-Write |
z |
number |
The z component of the Vector4. |
Read-Write |
w |
number |
The w component of the Vector4. |
Read-Write |
size |
number |
The magnitude of the Vector4. | Read-Only |
sizeSquared |
number |
The squared magnitude of the Vector4. | Read-Only |
Functions
Function Name | Return Type | Description | Tags |
---|---|---|---|
GetNormalized() |
Vector4 |
Returns a new Vector4 with size 1, but still pointing in the same direction. Returns (0, 0, 0, 0) if the vector is too small to be normalized. | None |
GetAbs() |
Vector4 |
Returns a new Vector4 with each component the absolute value of the component from this Vector4. | None |
Class Functions
Class Function Name | Return Type | Description | Tags |
---|---|---|---|
Vector4.Lerp(Vector4 from, Vector4 to, number progress) |
Vector4 |
Linearly interpolates between two vectors by the specified progress amount and returns the resultant Vector4. | None |
Operators
Operator Name | Return Type | Description | Tags |
---|---|---|---|
Vector4 + Vector4 |
Vector4 |
Component-wise addition. | None |
Vector4 + number |
Vector4 |
Adds the right-side number to each of the components in the left side and returns the resulting Vector4. | None |
Vector4 - Vector4 |
Vector4 |
Component-wise subtraction. | None |
Vector4 - number |
Vector4 |
Subtracts the right-side number from each of the components in the left side and returns the resulting Vector4. | None |
Vector4 * Vector4 |
Vector4 |
Component-wise multiplication. | None |
Vector4 * number |
Vector4 |
Multiplies each component of the Vector4 by the right-side number. | None |
number * Vector4 |
Vector4 |
Multiplies each component of the Vector4 by the left-side number. | None |
Vector4 / Vector4 |
Vector4 |
Component-wise division. | None |
Vector4 / number |
Vector4 |
Divides each component of the Vector4 by the right-side number. | None |
-Vector4 |
Vector4 |
Returns the negation of the Vector4. | None |
Vector4 .. Vector4 |
number |
Returns the dot product of the Vector4s. | None |
Vector4 ^ Vector4 |
Vector4 |
Returns the cross product of the Vector4s. | None |
Examples
Example using:
New
x
y
z
w
size
This example shows how a Color
can be converted into a Vector4
, which opens the possibility of some math operations that are available to the latter.
function ColorToVector4(color)
local v = Vector4.New()
v.x = color.r
v.y = color.g
v.z = color.b
v.w = color.a
return v
end
function GetMagnitudeOfColor(color)
local v = ColorToVector4(color)
return v.size
end
See also: Color.r
Last update:
January 13, 2022