Vector3

class Vector3(var x: Double = 0.0, var y: Double = 0.0, var z: Double = 0.0) : Iterable<Double>

A 3D vector: an ordered triplet of numbers (x, y, z).

A 3D vector can represent a point in 3D space, a direction and length in 3D space (the length being the Euclidean distance from (0, 0, 0) to (x, y, z)), or any arbitrary ordered triplet 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) in order.

Constructors

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

Properties

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

Returns the angle between this vector and v, in radians.

Link copied to clipboard
fun applyAxisAngle(axis: Vector3, angle: Double): Vector3

Applies a rotation specified by axis (a normalized vector) and angle (in radians) to this vector.

Link copied to clipboard
fun applyEuler(euler: Euler): Vector3

Applies the Euler rotation euler to this vector.

Link copied to clipboard

Multiplies this vector by the 3x3 matrix m.

Link copied to clipboard

Multiplies this vector (with an implicit 1 in the 4th dimension) by m, and divides by perspective.

Link copied to clipboard

Multiplies this vector by the normal matrix m and normalizes the result.

Link copied to clipboard

Applies the Quaternion q (assumed to have unit length) to this vector.

Link copied to clipboard
fun ceil(): Vector3

Rounds each component up to the nearest integer.

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

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

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

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

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

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

Link copied to clipboard
fun clone(): Vector3

Returns a new vector with the same components.

Link copied to clipboard

Copies the components of v into this instance.

Link copied to clipboard

Sets this vector to the cross product of this vector and v.

Link copied to clipboard

Sets this vector to the cross product of a and b.

Link copied to clipboard

Returns the distance from this vector to v.

Link copied to clipboard

Returns the squared distance from this vector to v.

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: Vector3): 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 Vector3 with equal components (component-wise ==, so NaN != NaN).

Link copied to clipboard
fun floor(): Vector3

Rounds each component down to the nearest integer.

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

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

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

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).

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: Vector3, alpha: Double): Vector3

Linearly interpolates from this vector toward v by alpha.

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

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

Link copied to clipboard

Returns the Manhattan distance from this vector to v.

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

Sets this vector to a * b (component-wise).

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
fun projectOnPlane(planeNormal: Vector3): Vector3

Projects this vector onto the plane with normal planeNormal (by subtracting this vector's projection onto the normal). Leaves the vector unchanged when planeNormal is a zero vector.

Link copied to clipboard

Projects this vector onto v.

Link copied to clipboard

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

Link copied to clipboard

Sets this vector to a uniformly random point on a unit sphere.

Link copied to clipboard
fun reflect(normal: Vector3): Vector3

Reflects this vector off a plane orthogonal to the (normalized) normal.

Link copied to clipboard
fun round(): Vector3

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): Vector3

Sets the vector components.

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

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

Link copied to clipboard

Sets the vector components from the RGB components of the color c (x = r, y = g, z = b).

Link copied to clipboard

Sets the vector components from the cylindrical coordinates c.

Link copied to clipboard

Sets the vector components from the cylindrical coordinates radius, theta (in radians) and y.

Link copied to clipboard

Sets the vector components from the Euler angles e.

Link copied to clipboard

Sets the vector components from column index of the 3x3 matrix m.

Link copied to clipboard

Sets the vector components from column index of the 4x4 matrix m.

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

Sets the vector components from the spherical coordinates s.

Link copied to clipboard
fun setFromSphericalCoords(radius: Double, phi: Double, theta: Double): Vector3

Sets the vector components from the spherical coordinates radius, phi (in radians) and theta (in radians).

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

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

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

Sets all vector components to scalar.

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
Link copied to clipboard

Transforms the direction of this vector by the upper-left 3x3 of the 4x4 matrix m, then normalizes the result.