gophergfx
    Preparing search index...

    Class Vector3

    This class holds the x,y,z components of a 3D point or vector. It includes linear algebra routines for working with vectors (e.g., dot product, cross product).

    Most of the functions in the class are defined both as member functions that can be called on a specific instance of Vector3 and as static functions. The static functions return a new result, leaving the original inputs unchanged, whereas, in general, member functions save the result in this vector itself and return void:

    const v = new Vector3(1, 2, 3);
    const w = new Vector3(4, 5, 6);

    // saves the result in n, v and w are unchanged.
    const n = Vector3.cross(v, w);

    // saves the result in v and returns null. v now becomes v crossed-with w.
    v.cross(w);
    Index
    • Constructs a Vector3 object from x, y, and z values

      Parameters

      • x: number = 0

        The x value for the Vector3

      • y: number = 0

        The y value for the Vector3

      • z: number = 0

        The z value for the Vector3

      Returns Vector3

    x: number
    y: number
    z: number
    BACK: Vector3 = ...

    A Vector3 object that points backward. (See note in the Vector3.ZERO docs for important usage info.)

    DOWN: Vector3 = ...

    A Vector3 object that points down. (See note in the Vector3.ZERO docs for important usage info.)

    FORWARD: Vector3 = ...

    A Vector3 object that points forward. (See note in the Vector3.ZERO docs for important usage info.)

    LEFT: Vector3 = ...

    A Vector3 object that points left. (See note in the Vector3.ZERO docs for important usage info.)

    ONE: Vector3 = ...

    A Vector3 object with all one values. (See note in the Vector3.ZERO docs for important usage info.)

    RIGHT: Vector3 = ...

    A Vector3 object that points right. (See note in the Vector3.ZERO docs for important usage info.)

    UP: Vector3 = ...

    A Vector3 object that points up. (See note in the Vector3.ZERO docs for important usage info.)

    X_AXIS: Vector3 = Vector3.RIGHT

    A Vector3 object that points along the x-axis. (See note in the Vector3.ZERO docs for important usage info.)

    Y_AXIS: Vector3 = Vector3.UP

    A Vector3 object that points along the y-axis. (See note in the Vector3.ZERO docs for important usage info.)

    Z_AXIS: Vector3 = Vector3.FORWARD

    A Vector3 object that points along the z-axis. (See note in the Vector3.ZERO docs for important usage info.)

    ZERO: Vector3 = ...

    A static property to provide quick access to a Vector3 with all of its x,y,z components equal to zero.

    • Computes the angle between this Vector3 and another Vector3

      Parameters

      Returns number

      The angle between the two Vectors

    • Creates a new Vector3 object with the same x, y, and z values as this Vector3

      Returns Vector3

      The cloned Vector3 object

    • Computes the cross product of two Vector3s and stores the result in the original Vector3.

      Parameters

      • v: Vector3

        The Vector3 to compute the cross product with.

      Returns void

    • Computes the distance between this Vector3 and another Vector3

      Parameters

      Returns number

      The distance between the two Vectors

    • Divides each component of the vector with that of another vector

      Parameters

      Returns void

    • Divides each component of the vector with a scalar value

      Parameters

      • n: number

        Scalar value to divide with

      Returns void

    • Compute the dot product of two Vector3 objects

      Parameters

      • v: Vector3

        The other Vector3 object

      Returns number

      The dot product of the two Vector3 objects

    • Checks if the x,y,z components of this Vector3 are exactly equal to those of the given Vector3

      Parameters

      • v: Vector3

        The Vector3 object to compare to

      Returns boolean

      A boolean value indicating if the Vector3 objects are equal

    • Checks if the x,y,z components of this Vector3 are equal (within a small value of epsilon) to those of the given Vector3.

      Parameters

      • v: Vector3

        The Vector3 object to compare to

      • epsilon: number = MathUtils.EPSILON

        A small value of acceptable variance to account for numerical instability

      Returns boolean

      A boolean value indicating if the Vector3 objects are equal

    • Calculates the length of a Vector3 object

      Returns number

      The length of the Vector3 object

    • Linearly interpolates between two Vector3s

      Parameters

      • v1: Vector3

        The starting Vector3

      • v2: Vector3

        The ending Vector3

      • alpha: number

        The interpolation amount (should be in the range [0, 1])

      Returns void

    • Multiplies this Vector3 by the given Vector3

      Parameters

      • v: Vector3

        The Vector3 object to multiply

      Returns void

    • Multiplies each component of the vector with a scalar value

      Parameters

      • n: number

        Scalar value to multiply with

      Returns void

    • Sets the x, y, and z values of a Vector3 object

      Parameters

      • x: number

        The x value to set

      • y: number

        The y value to set

      • z: number

        The z value to set

      Returns void

    • Sets this Vector3's position to the provided Matrix4's position

      Parameters

      • m: Matrix4

        The Matrix4 to get the position from

      Returns void

    • Sets this Vector3's scale to the provided Matrix4's scale

      Parameters

      • m: Matrix4

        The Matrix4 to get the scale from

      Returns void

    • Subtracts the given Vector3 from this Vector3

      Parameters

      • v: Vector3

        The Vector3 object to subtract

      Returns void

    • Transforms this Vector3 instance as a point with a given Matrix4

      Parameters

      • m: Matrix4

        The Matrix4 to transform this Vector3

      Returns void

    • Transforms this Vector3 instance as a direction with a given Matrix4, ignoring the translation component

      Parameters

      • m: Matrix4

        The Matrix4 to transform this Vector3

      Returns void

    • Adds two Vector3 objects together

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      Returns Vector3

      A new Vector3 object with the x, y, and z values equal to the sum of the corresponding values of the input vectors

    • Computes the angle in radians between two Vector3 objects

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      Returns number

      The angle in radians between the two input vectors

    • Creates a new Vector3 object that is a clone of the original

      Parameters

      • v: Vector3

        The Vector3 object to copy

      Returns Vector3

      A new Vector3 object with the same x, y, and z values as the original

    • Computes the distance between two Vector3 objects

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      Returns number

      The distance between the two input vectors

    • Divide two Vector3 objects

      Parameters

      • v1: Vector3

        The Vector3 object to divide

      • v2: Vector3

        The Vector3 object to divide by

      Returns Vector3

      A new Vector3 object with the x, y, and z values equal to the quotient of the corresponding values of the input vectors

    • Divides a Vector3 object by a scalar value

      Parameters

      • v: Vector3

        The Vector3 object

      • n: number

        The scalar value

      Returns Vector3

      A new Vector3 object with the x, y, and z values divided by the scalar value

    • Computes the dot product of two Vector3 objects

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      Returns number

      The dot product of the two input vectors

    • Checks if the x,y,z components of two Vector3 objects are exactly equal.

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      Returns boolean

      A boolean value indicating if the Vector3 objects are equal

    • Checks if the x,y,z components of two Vector3 objects are equal within a small value of epsilon.

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      • epsilon: number = MathUtils.EPSILON

        A small value of acceptable variance to account for numerical instability

      Returns boolean

      A boolean value indicating if the Vector3 objects are equal

    • Linearly interpolates between two Vector3 objects

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      • alpha: number

        The interpolation value between 0 and 1

      Returns Vector3

      A new Vector3 object that represents the result of interpolating between v1 and v2

    • Multiply two Vector3 objects

      Parameters

      • v1: Vector3

        The first Vector3 object

      • v2: Vector3

        The second Vector3 object

      Returns Vector3

      A new Vector3 object with the x, y, and z values equal to the product of the corresponding values of the input vectors

    • Multiplies a Vector3 object with a scalar value

      Parameters

      • v: Vector3

        The Vector3 object

      • n: number

        The scalar value

      Returns Vector3

      A new Vector3 object with the x, y, and z values multiplied by the scalar value

    • Normalizes a Vector3 object

      Parameters

      Returns Vector3

      A new Vector3 object with a magnitude of 1, pointing in the same direction as the original vector If the original vector is a zero vector, returns a new zero vector

    • Subtracts two Vector3 objects

      Parameters

      • v1: Vector3

        The Vector3 object to subtract from

      • v2: Vector3

        The Vector3 object to subtract

      Returns Vector3

      A new Vector3 object with the x, y, and z values equal to the difference of the corresponding values of the input vectors

    • Transforms a Vector3 object representing a point by a Matrix4

      Parameters

      • v: Vector3

        The Vector3 object to transform

      • m: Matrix4

        The Matrix4 object to transform the Vector3 by

      Returns Vector3

      A new Vector3 object that represents the result of transforming point v by m

    • Transforms a Vector3 object representing a direction by a Matrix4, ignoring the translation component

      Parameters

      • v: Vector3

        The Vector3 object to transform

      • m: Matrix4

        The Matrix4 object to transform the Vector3 by

      Returns Vector3

      A new Vector3 object that represents the result of transforming direction v by m