q5play
    Preparing search index...

    Class Vector

    Index

    Constructors

    • ↗ Constructs a new Vector object.

      Parameters

      • x: number

        x component of the vector

      • y: number

        y component of the vector

      • Optionalz: number

        optional. The z component of the vector

      Returns Vector

      await Canvas(200);
      background(0.8);

      let v = createVector(0, 0);
      circle(v.x, v.y, 50);

    Properties

    x: number

    ↗ The x component of the vector.

    y: number

    ↗ The y component of the vector.

    z: number

    ↗ The z component of the vector, if applicable.

    Methods

    • ↗ Adds a vector to this vector.

      Parameters

      Returns Vector

      resulting vector after addition

    • ↗ Copies this vector.

      Returns Vector

      a new vector with the same components as this one

    • ↗ Calculates the cross product of this vector and another vector.

      Parameters

      Returns Vector

      a new vector that is the cross product of this vector and the given vector

    • ↗ Calculates the distance between this vector and another vector.

      Parameters

      Returns number

      distance

    • ↗ Divides this vector by a scalar or element-wise by another vector.

      Parameters

      • n: number | Vector

        scalar to divide by, or a vector for element-wise division

      Returns Vector

      resulting vector after division

    • ↗ Calculates the dot product of this vector and another vector.

      Parameters

      Returns number

      dot product

    • ↗ Calculates the angle of rotation for this vector (only 2D vectors).

      Returns number

      angle of rotation

    • ↗ Linearly interpolates between this vector and another vector.

      Parameters

      • v: Vector

        vector to interpolate towards

      • amt: number

        amount of interpolation; a number between 0.0 (close to the current vector) and 1.0 (close to the target vector)

      Returns Vector

      this vector after interpolation

    • ↗ Limits the magnitude of the vector to the value used for the max parameter.

      Parameters

      • max: number

        maximum magnitude for the vector

      Returns Vector

      this vector after limiting

    • ↗ Calculates the magnitude (length) of the vector.

      Returns number

      magnitude of the vector

    • ↗ Multiplies this vector by a scalar or element-wise by another vector.

      Parameters

      • n: number | Vector

        scalar to multiply by, or a vector for element-wise multiplication

      Returns Vector

      resulting vector after multiplication

    • ↗ Normalizes the vector to a length of 1 (making it a unit vector).

      Returns Vector

      this vector after normalization

    • ↗ Rotates the vector by the given angle (only 2D vectors).

      Parameters

      • angle: number

        angle of rotation in radians

      Returns Vector

      this vector after rotation

    • ↗ Sets the components of the vector.

      Parameters

      • x: number

        x component

      • y: number

        y component

      • Optionalz: number

        optional. The z component

      Returns void

    • ↗ Rotates the vector to a specific angle without changing its magnitude.

      Parameters

      • angle: number

        angle in radians

      Returns Vector

      this vector after setting the heading

    • ↗ Sets the magnitude of the vector to the specified length.

      Parameters

      • len: number

        new length of the vector

      Returns Vector

      this vector after setting magnitude

    • ↗ Linearly interpolates between this vector and another vector, including the magnitude.

      Parameters

      • v: Vector

        vector to interpolate towards

      • amt: number

        amount of interpolation; a number between 0.0 (close to the current vector) and 1.0 (close to the target vector)

      Returns Vector

      this vector after spherical interpolation

    • ↗ Subtracts a vector from this vector.

      Parameters

      Returns Vector

      resulting vector after subtraction

    • Parameters

      • angle: number
      • Optionallength: number

      Returns Vector