Vector4
Four float components: X, Y, Z and W.
A struct with X, Y, Z and W components, represented as float in the installed C# SDK. Stores four numeric values. The receiving API determines W semantics; the type itself does not make W an alpha channel or the value a ready-made rotation. Assignment copies the value.
For projective calculations, check whether an operation expects homogeneous coordinates and performs division by W. Do not treat every Vector4 as a ready-to-use Vector3 point without that context.
Vector4 has no C# conversion to bool. Exact comparison with Vector4.Zero and tolerance-based comparison answer different questions; also validate finiteness for floating-point data.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Properties4
InfProperty
public static Vector4 Inf { get; }Infinity vector, a vector with all components set to @C#.INF.
ItemProperty
public float this[int index] { get; set; }Access vector components using their index.
OneProperty
public static Vector4 One { get; }One vector, a vector with all components set to 1.
ZeroProperty
public static Vector4 Zero { get; }Zero vector, a vector with all components set to 0.
Methods55
AbsVector4
CeilVector4
public Vector4 Ceil();Returns a new vector with all components rounded up (towards positive infinity).
Clamp2 overloads
public Vector4 Clamp(Vector4 min, Vector4 max);Returns a new vector with all components clamped between the components of Vector4.Min and Vector4.Max, by running @GlobalScope.clamp on each component.
| Name | Type | Default |
|---|---|---|
min | Vector4 | — |
max | Vector4 | — |
minThe vector with minimum allowed values.
maxThe vector with maximum allowed values.
Vector4The vector with all components clamped.
public Vector4 Clamp(float min, float max);Returns a new vector with all components clamped between the components of Vector4.Min and Vector4.Max, by running @GlobalScope.clamp on each component.
| Name | Type | Default |
|---|---|---|
min | float | — |
max | float | — |
minThe minimum allowed value.
maxThe maximum allowed value.
Vector4The vector with all components clamped.
CubicInterpolateVector4
public Vector4 CubicInterpolate(Vector4 b, Vector4 preA, Vector4 postB, float weight);Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.
| Name | Type | Default |
|---|---|---|
b | Vector4 | — |
preA | Vector4 | — |
postB | Vector4 | — |
weight | float | — |
bThe destination vector.
preAA vector before this vector.
postBA vector after b.
weightA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Vector4The interpolated vector.
CubicInterpolateInTimeVector4
public Vector4 CubicInterpolateInTime(Vector4 b, Vector4 preA, Vector4 postB, float weight, float t, float preAT, float postBT);Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.
It can perform smoother interpolation than Vector4.CubicInterpolate by the time values.
| Name | Type | Default |
|---|---|---|
b | Vector4 | — |
preA | Vector4 | — |
postB | Vector4 | — |
weight | float | — |
t | float | — |
preAT | float | — |
postBT | float | — |
bThe destination vector.
preAA vector before this vector.
postBA vector after b.
weightA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Vector4The interpolated vector.
Deconstructvoid
public void Deconstruct(out float x, out float y, out float z, out float w);Helper method for deconstruction into a tuple.
| Name | Type | Default |
|---|---|---|
x | float | — |
y | float | — |
z | float | — |
w | float | — |
DirectionToVector4
public Vector4 DirectionTo(Vector4 to);Returns the normalized vector pointing from this vector to to.
a.direction_to(b) is equivalent to (b - a).normalized(). See also Vector4.Normalized.
| Name | Type | Default |
|---|---|---|
to | Vector4 | — |
toThe other vector to point towards.
Vector4The direction from this vector to to.
DistanceSquaredTofloat
public float DistanceSquaredTo(Vector4 to);Returns the squared Euclidean distance between this vector and to.
This method runs faster than Vector4.DistanceTo, so prefer it if you need to compare vectors or need the squared distance for some formula.
| Name | Type | Default |
|---|---|---|
to | Vector4 | — |
toThe other vector to use.
floatThe squared distance between the two vectors.
DistanceTofloat
public float DistanceTo(Vector4 to);Returns the Euclidean distance between this vector and to.
| Name | Type | Default |
|---|---|---|
to | Vector4 | — |
toThe other vector to use.
floatThe distance between the two vectors.
Dotfloat
public float Dot(Vector4 with);Returns the dot product of this vector and with.
| Name | Type | Default |
|---|---|---|
with | Vector4 | — |
withThe other vector to use.
floatThe dot product of the two vectors.
Equals2 overloads
public bool Equals(Vector4 other);Returns true if the vectors are exactly equal.
Note: Due to floating-point precision errors, consider using
Vector4.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
other | Vector4 | — |
otherThe other vector.
boolWhether or not the vectors are exactly equal.
public override bool Equals(object? obj);Returns true if the vector is exactly equal
to the given object (obj).
Note: Due to floating-point precision errors, consider using
Vector4.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objThe object to compare with.
boolWhether or not the vector and the object are equal.
FloorVector4
public Vector4 Floor();Returns a new vector with all components rounded down (towards negative infinity).
GetHashCodeint
public override int GetHashCode();Serves as the hash function for Vector4.
intA hash code for this vector.
InverseVector4
public Vector4 Inverse();Returns the inverse of the vector. This is the same as Vector4(1.0 / v.x, 1.0 / v.y, 1.0 / v.z, 1.0 / v.w).
Vector4The inverse of this vector.
IsEqualApproxbool
public bool IsEqualApprox(Vector4 other);Returns true if this vector and to are approximately equal, by running @GlobalScope.is_equal_approx on each component.
| Name | Type | Default |
|---|---|---|
other | Vector4 | — |
otherThe other vector to compare.
boolWhether or not the vectors are approximately equal.
IsFinitebool
public bool IsFinite();Returns true if this vector is finite, by calling @GlobalScope.is_finite on each component.
boolWhether this vector is finite or not.
IsNormalizedbool
public bool IsNormalized();Returns true if the vector is normalized, i.e. its length is approximately equal to 1.
boolA bool indicating whether or not the vector is normalized.
IsZeroApproxbool
public bool IsZeroApprox();Returns true if this vector's values are approximately zero, by running @GlobalScope.is_zero_approx on each component.
This method is faster than using Vector4.IsEqualApprox with one value as a zero vector.
boolWhether or not the vector is approximately zero.
Lengthfloat
public float Length();Returns the length (magnitude) of this vector.
floatThe length of this vector.
LengthSquaredfloat
public float LengthSquared();Returns the squared length (squared magnitude) of this vector.
This method runs faster than Vector4.Length, so prefer it if you need to compare vectors or need the squared distance for some formula.
floatThe squared length of this vector.
LerpVector4
public Vector4 Lerp(Vector4 to, float weight);Returns the result of the linear interpolation between this vector and to by amount weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.
| Name | Type | Default |
|---|---|---|
to | Vector4 | — |
weight | float | — |
toThe destination vector for interpolation.
weightA value on the range of 0.0 to 1.0, representing the amount of interpolation.
Vector4The resulting vector of the interpolation.
Max2 overloads
public Vector4 Max(Vector4 with);Returns the component-wise maximum of this and with, equivalent to Vector4(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z), maxf(w, with.w)).
| Name | Type | Default |
|---|---|---|
with | Vector4 | — |
withThe other vector to use.
Vector4The resulting maximum vector.
public Vector4 Max(float with);Returns the component-wise maximum of this and with, equivalent to Vector4(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z), maxf(w, with.w)).
| Name | Type | Default |
|---|---|---|
with | float | — |
withThe other value to use.
Vector4The resulting maximum vector.
MaxAxisIndexVector4.Axis
public Vector4.Axis MaxAxisIndex();Returns the axis of the vector's highest value. See AXIS_* constants. If all components are equal, this method returns Vector4.Axis.X.
Vector4.AxisThe index of the highest axis.
Min2 overloads
public Vector4 Min(Vector4 with);Returns the component-wise minimum of this and with, equivalent to Vector4(minf(x, with.x), minf(y, with.y), minf(z, with.z), minf(w, with.w)).
| Name | Type | Default |
|---|---|---|
with | Vector4 | — |
withThe other vector to use.
Vector4The resulting minimum vector.
public Vector4 Min(float with);Returns the component-wise minimum of this and with, equivalent to Vector4(minf(x, with.x), minf(y, with.y), minf(z, with.z), minf(w, with.w)).
| Name | Type | Default |
|---|---|---|
with | float | — |
withThe other value to use.
Vector4The resulting minimum vector.
MinAxisIndexVector4.Axis
public Vector4.Axis MinAxisIndex();Returns the axis of the vector's lowest value. See AXIS_* constants. If all components are equal, this method returns Vector4.Axis.W.
Vector4.AxisThe index of the lowest axis.
NormalizedVector4
public Vector4 Normalized();Returns the result of scaling the vector to unit length. Equivalent to v / v.length(). Returns (0, 0, 0, 0) if v.length() == 0. See also Vector4.IsNormalized.
Note: This function may return incorrect values if the input vector length is near zero.
Vector4A normalized version of the vector.
PosMod2 overloads
public Vector4 PosMod(Vector4 modv);Returns a vector composed of the @GlobalScope.fposmod of this vector's components and mod.
| Name | Type | Default |
|---|---|---|
modv | Vector4 | — |
modvA vector representing the divisors of the operation.
public Vector4 PosMod(float mod);Returns a vector composed of the @GlobalScope.fposmod of this vector's components and mod.
| Name | Type | Default |
|---|---|---|
mod | float | — |
modA value representing the divisor of the operation.
RoundVector4
public Vector4 Round();Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
Vector4The rounded vector.
SignVector4
public Vector4 Sign();Returns a new vector with each component set to 1.0 if it's positive, -1.0 if it's negative, and 0.0 if it's zero. The result is identical to calling @GlobalScope.sign on each component.
Vector4A vector with all components as either 1, -1, or 0.
Snapped2 overloads
public Vector4 Snapped(Vector4 step);Returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.
| Name | Type | Default |
|---|---|---|
step | Vector4 | — |
stepA vector value representing the step size to snap to.
Vector4The snapped vector.
public Vector4 Snapped(float step);Returns a new vector with each component snapped to the nearest multiple of the corresponding component in step. This can also be used to round the components to an arbitrary number of decimals.
| Name | Type | Default |
|---|---|---|
step | float | — |
stepThe step size to snap to.
Vector4The snapped vector.
ToString2 overloads
public override string ToString();Converts this Vector4 to a string.
stringA string representation of this vector.
public string ToString(string? format);Converts this Vector4 to a string with the given format.
| Name | Type | Default |
|---|---|---|
format | string | — |
stringA string representation of this vector.
op_AdditionVector4
public static Vector4 operator +(Vector4 left, Vector4 right);Adds each component of the Vector4
with the components of the given Vector4.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
Vector4The added vector.
op_Division2 overloads
public static Vector4 operator /(Vector4 vec, Vector4 divisorv);Divides each component of the Vector4
by the components of the given Vector4.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
divisorv | Vector4 | — |
vecThe dividend vector.
divisorvThe divisor vector.
Vector4The divided vector.
public static Vector4 operator /(Vector4 vec, float divisor);Divides each component of the Vector4
by the given System.Single.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
divisor | float | — |
vecThe dividend vector.
divisorThe divisor value.
Vector4The divided vector.
op_Equalitybool
public static bool operator ==(Vector4 left, Vector4 right);Returns true if the vectors are exactly equal.
Note: Due to floating-point precision errors, consider using
Vector4.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
boolWhether or not the vectors are exactly equal.
op_GreaterThanbool
public static bool operator >(Vector4 left, Vector4 right);Compares two Vector4 vectors by first checking if
the X value of the left vector is greater than
the X value of the right vector.
If the X values are exactly equal, then it repeats this check
with the Y, Z and finally W values of the two vectors.
This operator is useful for sorting vectors.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
boolWhether or not the left is greater than the right.
op_GreaterThanOrEqualbool
public static bool operator >=(Vector4 left, Vector4 right);Compares two Vector4 vectors by first checking if
the X value of the left vector is greater than
or equal to the X value of the right vector.
If the X values are exactly equal, then it repeats this check
with the Y, Z and finally W values of the two vectors.
This operator is useful for sorting vectors.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
boolWhether or not the left is greater than or equal to the right.
op_Inequalitybool
public static bool operator !=(Vector4 left, Vector4 right);Returns true if the vectors are not equal.
Note: Due to floating-point precision errors, consider using
Vector4.IsEqualApprox instead, which is more reliable.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
boolWhether or not the vectors are not equal.
op_LessThanbool
public static bool operator <(Vector4 left, Vector4 right);Compares two Vector4 vectors by first checking if
the X value of the left vector is less than
the X value of the right vector.
If the X values are exactly equal, then it repeats this check
with the Y, Z and finally W values of the two vectors.
This operator is useful for sorting vectors.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
boolWhether or not the left is less than the right.
op_LessThanOrEqualbool
public static bool operator <=(Vector4 left, Vector4 right);Compares two Vector4 vectors by first checking if
the X value of the left vector is less than
or equal to the X value of the right vector.
If the X values are exactly equal, then it repeats this check
with the Y, Z and finally W values of the two vectors.
This operator is useful for sorting vectors.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
boolWhether or not the left is less than or equal to the right.
op_Modulus2 overloads
public static Vector4 operator %(Vector4 vec, Vector4 divisorv);Gets the remainder of each component of the Vector4
with the components of the given Vector4.
This operation uses truncated division, which is often not desired
as it does not work well with negative numbers.
Consider using Vector4.PosMod instead
if you want to handle negative numbers.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
divisorv | Vector4 | — |
vecThe dividend vector.
divisorvThe divisor vector.
Vector4The remainder vector.
public static Vector4 operator %(Vector4 vec, float divisor);Gets the remainder of each component of the Vector4
with the components of the given System.Single.
This operation uses truncated division, which is often not desired
as it does not work well with negative numbers.
Consider using Vector4.PosMod instead
if you want to handle negative numbers.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
divisor | float | — |
vecThe dividend vector.
divisorThe divisor value.
Vector4The remainder vector.
op_Multiply3 overloads
public static Vector4 operator *(Vector4 left, Vector4 right);Multiplies each component of the Vector4
by the components of the given Vector4.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
Vector4The multiplied vector.
public static Vector4 operator *(Vector4 vec, float scale);Multiplies each component of the Vector4
by the given System.Single.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
scale | float | — |
vecThe vector to multiply.
scaleThe scale to multiply by.
Vector4The multiplied vector.
public static Vector4 operator *(float scale, Vector4 vec);Multiplies each component of the Vector4
by the given System.Single.
| Name | Type | Default |
|---|---|---|
scale | float | — |
vec | Vector4 | — |
scaleThe scale to multiply by.
vecThe vector to multiply.
Vector4The multiplied vector.
op_SubtractionVector4
public static Vector4 operator -(Vector4 left, Vector4 right);Subtracts each component of the Vector4
by the components of the given Vector4.
| Name | Type | Default |
|---|---|---|
left | Vector4 | — |
right | Vector4 | — |
leftThe left vector.
rightThe right vector.
Vector4The subtracted vector.
op_UnaryNegationVector4
public static Vector4 operator -(Vector4 vec);Returns the negative value of the Vector4.
This is the same as writing new Vector4(-v.X, -v.Y, -v.Z, -v.W).
This operation flips the direction of the vector while
keeping the same magnitude.
With floats, the number zero can be either positive or negative.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
vecThe vector to negate/flip.
Vector4The negated/flipped vector.
op_UnaryPlusVector4
public static Vector4 operator +(Vector4 vec);Returns the same value as if the + was not there.
Unary + does nothing, but sometimes it can make your
code more readable.
| Name | Type | Default |
|---|---|---|
vec | Vector4 | — |
vecThe vector to do nothing to.
Vector4The original vector.
Fields and constants4
WField
public float W;The vector's W component. Also accessible by using the index position [3].
XField
public float X;The vector's X component. Also accessible by using the index position [0].
YField
public float Y;The vector's Y component. Also accessible by using the index position [1].
ZField
public float Z;The vector's Z component. Also accessible by using the index position [2].
Vector4.Axis
| Value | Description |
|---|---|
W = 3 | Enumerated value for the W axis. Returned by |
X = 0 | Enumerated value for the X axis. Returned by |
Y = 1 | Enumerated value for the Y axis. Returned by |
Z = 2 | Enumerated value for the Z axis. Returned by |