Stores and manipulates a threedimensional vector comprised of the components x, y and z

           +y
            |__ +x
           /
         +z   

Authors

Jascha Karagöl, HFU, 2019 | Jirka Dell'Oro-Friedl, HFU, 2019-2022 | Jonas Plotzky, HFU, 2023-2025

Hierarchy (view full)

Implements

Constructors

Properties

x: number
y: number
z: number
keys: readonly ["x", "y", "z"] = ...

Array of the keys of a vector. Allows to translate an index (0, 1, 2) to a key ("x", "y", "z") or to iterate over a vector.

Accessors

  • get magnitudeSquared(): number
  • Returns the square of the magnitude of the vector without calculating a square root. Faster for simple proximity evaluation.

    Returns number

  • get type(): string
  • Retrieves the type of this mutable subclass as the name of the runtime class

    Returns string

    The type of the mutable

Methods

  • Calls a defined callback function on each component of the vector and assigns the result to the component. Similar to Vector3.map but mutates this vector instead of creating a new one.

    Parameters

    • _function: ((_value, _index, _component, _vector) => number)
        • (_value, _index, _component, _vector): number
        • Parameters

          • _value: number
          • _index: number
          • _component: "x" | "y" | "z"
          • _vector: Vector3

          Returns number

    Returns Vector3

    A reference to this vector.

  • Returns true if the coordinates of this and the given vector are to be considered identical within the given tolerance TODO: examine, if tolerance as criterium for the difference is appropriate with very large coordinate values or if _tolerance should be multiplied by coordinate value

    Parameters

    • _compare: Vector3
    • _tolerance: number = Number.EPSILON

    Returns boolean

  • Set the values of this object from the given array starting at the given offset.

    Parameters

    • _array: ArrayLike<number>

      The array to read the values from.

    • _offset: number = 0

      (optional) The offset to start reading from.

    Returns this

    A reference to this instance.

  • Collect applicable attributes of the instance and copies of their values in a Mutator-object. By default, a mutator cannot be extended, since extensions are not available in the object the mutator belongs to. A mutator may be reduced by the descendants of Mutable to contain only the properties needed.

    Returns Mutator

  • Returns true if the position described by this is within a cube with the opposite corners 1 and 2.

    Parameters

    Returns boolean

  • Returns true if the position described by this is within a sphere with the given center and radius.

    Parameters

    Returns boolean

  • Calls a defined callback function on each component of the vector, and returns a new vector that contains the results. Similar to Array.map.

    Parameters

    • _function: ((_value, _index, _component, _vector) => number)
        • (_value, _index, _component, _vector): number
        • Parameters

          • _value: number
          • _index: number
          • _component: "x" | "y" | "z"
          • _vector: Vector3

          Returns number

    • _out: Vector3 = ...

      (optional) the receiving vector.

    Returns Vector3

    _out or a new vector if none is provided.

  • Updates the attribute values of the instance according to the state of the mutator. The mutation may be restricted to a subset of the mutator and the event dispatching suppressed. Uses mutateBase, but can be overwritten in subclasses

    Parameters

    Returns void

  • Copy the values of this object into the given array starting at the given offset. Creates a new array if none is provided.

    Type Parameters

    • T extends {
          [n: number]: number;
      } = number[]

    Parameters

    • _out: T = ...

      (optional) The receiving array.

    • _offset: number = 0

      (optional) The offset to start writing to.

    Returns T

    _out or a new array if none is provided.

  • Transforms this vector by the given matrix or rotation quaternion. Including or exluding the translation if a matrix is passed. Including is the default, excluding will only rotate and scale this vector.

    Parameters

    Returns Vector3

    A reference to this vector.

  • Creates a cartesian vector from geographic coordinates.

    Parameters

    • _longitude: number = 0
    • _latitude: number = 0
    • _magnitude: number = 1
    • _out: Vector3 = ...

      Optional vector to store the result in.

    Returns Vector3

  • Creates and returns a vector which is a copy of the given vector scaled to the given length.

    Parameters

    • _vector: Vector3
    • _length: number = 1
    • _out: Vector3 = ...

      Optional vector to store the result in.

    Returns Vector3

  • Calculates and returns the reflection of the incoming vector at the given normal vector. The length of normal should be 1.

    _________________________
              /|\
    incoming / | \ reflection
            /  |  \   
             normal
    

    Parameters

    Returns Vector3

  • Smoothly interpolates between two vectors based on a critically damped spring model. Allows to smooth toward a moving target with an ease-in/ease-out motion maintaining a continuous velocity. Does not overshoot.

    Parameters

    • _current: Vector3

      The current value.

    • _target: Vector3

      The target value.

    • _velocity: Vector3

      The velocity at which the value is moving. This value is modified by the function and must be maintained in the outside context.

    • _smoothTime: number

      The time it would take for the value to reach the target if it were moving at maximum velocity for the entire duration. When following a moving target the smooth time equals the lag time allowing to calculate the lag distance = target velocity * smooth time.

    • _timeFrame: number

      The elapsed time since the last call to the function.

    • _maxSpeed: number = Infinity

      An optional maximum speed that limits the velocity of the value. Defaults to Infinity.

    • _out: Vector3 = ...

      Optional vector to store the result in.

    Returns Vector3

    Source

    from Andrew Kirmse, Game Programming Gems 4, Chapter 1.10

  • Creates and returns a vector through transformation of the given vector by the given matrix or rotation quaternion.

    Parameters

    Returns Vector3