Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vec3

An immutable 3d vector with x, y and z values.

Used for positions, normals and other 3d entities.

Hierarchy

  • Vec3

Index

Constructors

constructor

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

    Parameters

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

    Returns Vec3

Properties

Readonly x

x: number

The x coordinate of the vector

Readonly y

y: number

The y coordinate of the vector

Readonly z

z: number

The z coordinate of the vector

Methods

equals

  • Returns true if the vectors are equal

    Parameters

    Returns boolean

getLength

  • getLength(): number
  • Returns the length of the vector (sqrt(x^2 + y^2 + z^2)).

    Returns number

getLengthSquared

  • getLengthSquared(): number
  • Returns the squared length of the vector

    Returns number

getNegated

  • getNegated(): Vec3
  • Returns a negated version of the vector.

    Returns Vec3

getNormalized

  • getNormalized(): Vec3
  • Returns a normalized version of the vector.

    Returns Vec3

getPointDistance

  • getPointDistance(otherPoint: Vec3): number
  • Returns the distance between this point and otherPoint

    Parameters

    Returns number

getPointDistanceSquared

  • getPointDistanceSquared(otherPoint: Vec3Like): number
  • Returns the squared distance between this point and otherPoint

    Parameters

    Returns number

Static add

Static cross

Static dot

  • Returns the dot product of the 2 vectors

    Parameters

    Returns number

Static from

  • Creates a new Vec3 instance from any object with x, y and z properties.

    Parameters

    Returns Vec3

Static fromArray

  • fromArray(arr: ArrayLike<number>): Vec3
  • Creates a new Vec3 instance from the first 3 elements of the given array.

    Parameters

    • arr: ArrayLike<number>

    Returns Vec3

Static negate

  • Returns the negation of the given vector

    Parameters

    Returns Vec3

Static scale

  • Returns the result of scaling the given vector by the given factor

    Parameters

    Returns Vec3

Static sub

  • Returns the result of subtracting vector b from vector a

    Parameters

    Returns Vec3

Static transformPoint

  • Returns a new vector with the given vector transforms as a point.

    Transforms the vector as a point by multiplying it with the given matrix. This will both rotate and translate the vector p. Assumes the matrix m doesn't contain any perspective projection.

    Parameters

    Returns Vec3

Static transformVector

  • Returns a new vector with the given vector transforms as a vector.

    Transforms the vector as a vector by multiplying it with the given matrix. This will only rotate the vector. The translation part of the matrix will be ignored. Assumes the matrix m doesn't contain any perspective projection.

    Parameters

    Returns Vec3

Generated using TypeDoc