Vector4

class Vector4(var x: Double = 0.0, var y: Double = 0.0, var z: Double = 0.0, var w: Double = 1.0) : Iterable<Double>

A 4D vector: an ordered quadruplet of numbers (x, y, z, w).

A 4D vector can represent a point in 4D space, a direction and length in 4D space (the length being the Euclidean distance from (0, 0, 0, 0) to (x, y, z, w)), or any arbitrary ordered quadruplet of numbers.

Vectors are mutable and not thread-safe; confine an instance (and any object graph holding it) to a single thread, exactly as in three.js. Most methods mutate this and return it for chaining.

Iterating a vector yields its components (x, y, z, w) in order.

Note: the w component defaults to 1.0 (matching three.js), unlike the other three components which default to 0.0.

Constructors

Link copied to clipboard
constructor(x: Double = 0.0, y: Double = 0.0, z: Double = 0.0, w: Double = 1.0)

Properties

Link copied to clipboard

Alias for w.

Link copied to clipboard
var w: Double

The w value of this vector.

Link copied to clipboard

Alias for z.

Link copied to clipboard
var x: Double

The x value of this vector.

Link copied to clipboard
var y: Double

The y value of this vector.

Link copied to clipboard
var z: Double

The z value of this vector.

Functions

Link copied to clipboard

Adds v to this instance.

Link copied to clipboard

Adds the scalar s to all components.

Link copied to clipboard

Adds v scaled by s to this instance.

Link copied to clipboard

Sets this vector to a + b.

Link copied to clipboard

Multiplies this vector by the 4x4 matrix m.

Link copied to clipboard
fun ceil(): Vector4

Rounds each component up to the nearest integer.

Link copied to clipboard
fun clamp(min: Vector4, max: Vector4): Vector4

Clamps each component into the range [min, max] (assumed component-wise min <= max).

Link copied to clipboard
fun clampLength(min: Double, max: Double): Vector4

Clamps this vector's length into [min, max].

Link copied to clipboard
fun clampScalar(minVal: Double, maxVal: Double): Vector4

Clamps each component into the scalar range [minVal, maxVal].

Link copied to clipboard
fun clone(): Vector4

Returns a new vector with the same components.

Link copied to clipboard

Copies the components of v into this instance.

Link copied to clipboard

Divides this instance component-wise by v.

Link copied to clipboard

Divides all components by scalar.

Link copied to clipboard
fun dot(v: Vector4): Double

Returns the dot product of this vector and v.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Structural equality: true when other is a Vector4 with equal components (component-wise ==, so NaN != NaN).

Link copied to clipboard
fun floor(): Vector4

Rounds each component down to the nearest integer.

Link copied to clipboard
fun fromArray(array: DoubleArray, offset: Int = 0): Vector4

Sets x = array[offset], y = array[offset + 1], z = array[offset + 2], w = array[offset + 3].

Link copied to clipboard
fun fromBufferAttribute(attribute: AttributeLike, index: Int): Vector4

Sets this vector's components from attribute at index.

Link copied to clipboard
fun getComponent(index: Int): Double

Returns the component at index (0 = x, 1 = y, 2 = z, 3 = w).

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open operator override fun iterator(): Iterator<Double>
Link copied to clipboard
fun length(): Double

Returns the Euclidean length of this vector.

Link copied to clipboard

Returns the squared Euclidean length of this vector.

Link copied to clipboard
fun lerp(v: Vector4, alpha: Double): Vector4

Linearly interpolates from this vector toward v by alpha.

Link copied to clipboard
fun lerpVectors(v1: Vector4, v2: Vector4, alpha: Double): Vector4

Sets this vector to the linear interpolation of v1 and v2 by alpha.

Link copied to clipboard

Returns the Manhattan length of this vector.

Link copied to clipboard

Sets each component to the maximum of itself and v's corresponding component.

Link copied to clipboard

Sets each component to the minimum of itself and v's corresponding component.

Link copied to clipboard

Multiplies this instance component-wise by v.

Link copied to clipboard

Multiplies all components by scalar.

Link copied to clipboard

Negates each component.

Link copied to clipboard

Normalizes this vector to unit length (leaves a zero vector unchanged).

Link copied to clipboard

Sets each component to a pseudo-random value in [0, 1).

Link copied to clipboard
fun round(): Vector4

Rounds each component to the nearest integer (halves toward +infinity, as JS Math.round).

Link copied to clipboard

Rounds each component toward zero.

Link copied to clipboard
fun set(x: Double, y: Double, z: Double, w: Double): Vector4

Sets the vector components.

Link copied to clipboard

Sets the x, y and z components of this vector to the quaternion q's axis and w to the angle.

Link copied to clipboard

Sets the x, y and z components of this vector to the axis of rotation and w to the angle, from the 4x4 matrix m (whose upper-left 3x3 is assumed to be a pure rotation matrix).

Link copied to clipboard
fun setComponent(index: Int, value: Double): Vector4

Sets the component at index (0 = x, 1 = y, 2 = z, 3 = w) to value.

Link copied to clipboard

Sets the vector components to the position elements of the transformation matrix m.

Link copied to clipboard
fun setLength(length: Double): Vector4

Sets this vector's length to length, preserving direction.

Link copied to clipboard
fun setScalar(scalar: Double): Vector4

Sets all vector components to scalar.

Link copied to clipboard

Sets the vector's w component.

Link copied to clipboard

Sets the vector's x component.

Link copied to clipboard

Sets the vector's y component.

Link copied to clipboard

Sets the vector's z component.

Link copied to clipboard

Subtracts v from this instance.

Link copied to clipboard

Subtracts the scalar s from all components.

Link copied to clipboard

Sets this vector to a - b.

Link copied to clipboard
fun toArray(array: MutableList<Double> = mutableListOf(), offset: Int = 0): MutableList<Double>

Writes this vector's components into array at offset, growing the list as needed, and returns it.

Link copied to clipboard
open override fun toString(): String