API reference
API reference
Select your platform
No SDKs available
No versions available

Vector4 Class

Modifiers: open
Represents a 4D vector with x, y, z, and w floating-point components.
Used for quaternion representation and homogeneous coordinates. Provides standard vector arithmetic, dot product, normalization, linear interpolation, and distance calculations. Supports operator overloading and Kotlin destructuring.

See Also

Signature

open class Vector4(var x: Float, var y: Float, var z: Float, var w: Float)

Constructors

Vector4 ( v )
Constructor that takes a single float value and initializes all components to that value.
Signature
constructor(v: Float)
Parameters
v: Float  The value to initialize all components with.
Returns
Vector4
Vector4 ( x , y , z , w )
Signature
constructor(x: Float, y: Float, z: Float, w: Float)
Parameters
x: Float  The x coordinate component.
y: Float  The y coordinate component.
z: Float  The z coordinate component.
w: Float  The w component (quaternion scalar or homogeneous coordinate).
Returns
Vector4

Properties

w : Float
[Get][Set]
The w component (quaternion scalar or homogeneous coordinate).
Signature
open var w: Float
x : Float
[Get][Set]
The x coordinate component.
Signature
open var x: Float
y : Float
[Get][Set]
The y coordinate component.
Signature
open var y: Float
z : Float
[Get][Set]
The z coordinate component.
Signature
open var z: Float

Methods

add ( v )
Performs vector addition.
Signature
fun add(v: Vector4): Vector4
Parameters
v: Vector4  The vector to add.
Returns
Vector4  The resulting vector.
component1 ()
Signature
operator fun component1(): Float
Returns
Float
component2 ()
Signature
operator fun component2(): Float
Returns
Float
component3 ()
Signature
operator fun component3(): Float
Returns
Float
component4 ()
Signature
operator fun component4(): Float
Returns
Float
copy ()
Returns a copy of this vector.
Signature
fun copy(): Vector4
Returns
Vector4  A copy of this vector.
distanceTo ( v )
Calculates the distance between two vectors.
Signature
fun distanceTo(v: Vector4): Float
Parameters
v: Vector4  The other vector to calculate the distance to.
Returns
Float  The distance between the two vectors.
div ( v )
Overloads the div operator to perform scalar division.
Signature
operator fun div(v: Float): Vector4
Parameters
v: Float  The scalar to divide by.
Returns
Vector4  The resulting vector.
divide ( v )
Performs scalar division.
Signature
fun divide(v: Float): Vector4
Parameters
v: Float  The scalar to divide by.
Returns
Vector4  The resulting vector.
dot ( v )
Calculates the dot product of two vectors.
Signature
fun dot(v: Vector4): Float
Parameters
v: Vector4  The vector to calculate the dot product with.
Returns
Float  The dot product.
equals ( other )
Signature
open operator override fun equals(other: Any?): Boolean
Parameters
other: Any?
Returns
Boolean
hashCode ()
Signature
open override fun hashCode(): Int
Returns
Int
length ()
Calculates the length of the vector.
Signature
fun length(): Float
Returns
Float  The length of the vector.
lerp ( dest , ratio )
Linearly interpolates between two vectors.
Signature
fun lerp(dest: Vector4, ratio: Float): Vector4
Parameters
dest: Vector4  The destination vector to interpolate towards.
ratio: Float  The interpolation ratio, where 0 means no interpolation (i.e., the current vector) and 1 means full interpolation (i.e., the destination vector).
Returns
Vector4  The interpolated vector.
minus ( v )
Overloads the minus operator to perform vector subtraction.
Signature
operator fun minus(v: Vector4): Vector4
Parameters
v: Vector4  The vector to subtract.
Returns
Vector4  The resulting vector.
multiply ( v )
Performs vector multiplication.
Signature
fun multiply(v: Vector4): Vector4
Parameters
v: Vector4  The vector to multiply.
Returns
Vector4  The resulting vector.
multiply ( v )
Performs scalar multiplication.
Signature
fun multiply(v: Float): Vector4
Parameters
v: Float  The scalar to multiply by.
Returns
Vector4  The resulting vector.
negate ()
Negates the vector.
Signature
fun negate(): Vector4
Returns
Vector4  The negated vector.
normalize ()
Normalizes the vector.
Signature
fun normalize(): Vector4
Returns
Vector4  A new vector representing the normalization of this vector, or (0, 0, 0, 0) if the length of this vector is 0.
plus ( v )
Overloads the plus operator to perform vector addition.
Signature
operator fun plus(v: Vector4): Vector4
Parameters
v: Vector4  The vector to add.
Returns
Vector4  The resulting vector.
setW ( w )
Signature
fun setW(w: Float): Vector4
Parameters
w: Float
Returns
Vector4
setX ( x )
Signature
fun setX(x: Float): Vector4
Parameters
x: Float
Returns
Vector4
setY ( y )
Signature
fun setY(y: Float): Vector4
Parameters
y: Float
Returns
Vector4
setZ ( z )
Signature
fun setZ(z: Float): Vector4
Parameters
z: Float
Returns
Vector4
sub ( v )
Performs vector subtraction.
Signature
fun sub(v: Vector4): Vector4
Parameters
v: Vector4  The vector to subtract.
Returns
Vector4  The resulting vector.
times ( v )
Overloads the times operator to perform component-wise multiplication.
Signature
operator fun times(v: Vector4): Vector4
Parameters
v: Vector4  The vector to multiply.
Returns
Vector4  The resulting vector.
times ( v )
Overloads the times operator to perform scalar multiplication.
Signature
operator fun times(v: Float): Vector4
Parameters
v: Float  The scalar to multiply by.
Returns
Vector4  The resulting vector.
toString ()
Signature
open override fun toString(): String
Returns
String
unaryMinus ()
Overloads the unary minus operator to negate the vector.
Signature
operator fun unaryMinus(): Vector4
Returns
Vector4  The negated vector.