Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vec3

3-dimensional vector

example
const v = new Vec3(1, 2, 3)
console.log('x=' + v.x) // x=1

Hierarchy

  • Vec3

Index

Constructors

constructor

  • new Vec3(x?: number, y?: number, z?: number): Vec3

Methods

addScaledVector

  • addScaledVector(scalar: number, vector: Vec3, target?: Vec3): Vec3
  • Scale a vector and add it to this vector. Save the result in "target". (target = this + vector * scalar)

    Parameters

    • scalar: number
    • vector: Vec3
    • target: Vec3 = ...

      The vector to save the result in.

    Returns Vec3

almostEquals

  • almostEquals(vector: Vec3, precision?: number): boolean
  • Check if a vector equals is almost equal to another one.

    Parameters

    • vector: Vec3
    • precision: number = 1e-6

    Returns boolean

almostZero

  • almostZero(precision?: number): boolean
  • Check if a vector is almost zero

    Parameters

    • precision: number = 1e-6

    Returns boolean

clone

copy

cross

crossmat

distanceSquared

  • distanceSquared(p: Vec3): number
  • Get squared distance from this point to another point

    Parameters

    Returns number

distanceTo

  • distanceTo(p: Vec3): number
  • Get distance from this point to another point

    Parameters

    Returns number

dot

  • dot(vector: Vec3): number

isAntiparallelTo

  • isAntiparallelTo(vector: Vec3, precision?: number): boolean
  • Check if the vector is anti-parallel to another vector.

    Parameters

    • vector: Vec3
    • Optional precision: number

      Set to zero for exact comparisons

    Returns boolean

length

  • length(): number

lengthSquared

  • lengthSquared(): number
  • Get the squared length of the vector.

    Returns number

lerp

  • lerp(vector: Vec3, t: number, target: Vec3): void
  • Do a linear interpolation between two vectors

    Parameters

    • vector: Vec3
    • t: number

      A number between 0 and 1. 0 will make this function return u, and 1 will make it return v. Numbers in between will generate a vector in between them.

    • target: Vec3

    Returns void

negate

  • Make the vector point in the opposite direction.

    Parameters

    • target: Vec3 = ...

      Optional target to save in

    Returns Vec3

normalize

  • normalize(): number
  • Normalize the vector. Note that this changes the values in the vector.

    Returns number

    Returns the norm of the vector

scale

  • scale(scalar: number, target?: Vec3): Vec3
  • Multiply all the components of the vector with a scalar.

    Parameters

    • scalar: number
    • target: Vec3 = ...

      The vector to save the result in.

    Returns Vec3

set

  • set(x: number, y: number, z: number): Vec3
  • Set the vectors' 3 elements

    Parameters

    • x: number
    • y: number
    • z: number

    Returns Vec3

setZero

  • setZero(): void
  • Set all components of the vector to zero.

    Returns void

tangents

  • Compute two artificial tangents to the vector

    Parameters

    • t1: Vec3

      Vector object to save the first tangent in

    • t2: Vec3

      Vector object to save the second tangent in

    Returns void

toArray

  • toArray(): [number, number, number]
  • Converts to an array

    Returns [number, number, number]

toString

  • toString(): string

unit

  • Get the version of this vector that is of length 1.

    Parameters

    • target: Vec3 = ...

      Optional target to save in

    Returns Vec3

    Returns the unit vector

vadd

vmul

  • Multiply the vector with an other vector, component-wise.

    Parameters

    • vector: Vec3
    • target: Vec3 = ...

      The vector to save the result in.

    Returns Vec3

vsub