Class Vect

Constructors

  • Parameters

    • Optional x: number
    • Optional y: number

    Returns Vect

Properties

x: number
y: number

Methods

  • Parameters

    Returns this

  • Adds a vector.

    Parameters

    Returns this

    Chainable

  • Gives the angle between a reference vector and this. The result is between [PI,-PI). In school coordinates, the angle is counted counter clockwise from reference to the vector. In game coordinates, the angle is counted clockwise from reference to the vector.

    Parameters

    • Optional ref: Vect

      [optional] reference vector. default: (1,0).

    Returns number

  • Not exactly the cross product, because seems not to be defined for 2d vectors.

    "Gives the Z-component of 3d cross product, if the two given vectors where extended to 3d vectors." or "Determinant of a 2x2 matrix build by the two vectors."

    Usefull to find the orientation of the two vectors.

    Parameters

    Returns number

  • Euclidean distance of two vectors.

    Parameters

    Returns number

  • Quadratic distance of two vectors.

    Parameters

    Returns number

  • Scalar division. Each coordinate will be divided by the given scalar.

    Parameters

    • s: number

    Returns this

    Chainable

  • Dot product of this and the given vector.

    Parameters

    Returns number

  • y isLeftOf

    Parameters

    Returns boolean

  • Parameters

    Returns boolean

  • Euclidean norm/length/magnitude of the vector.

    Returns number

  • Quadratic length of the vector. y lengthSq

    Returns number

  • Manhatten/city block/Taxicab distance

    Parameters

    Returns number

  • Scalar multiplication. Each coordinate will be multiplied with the given scalar.

    Parameters

    • s: number

    Returns this

    Chainable

  • Normalize the given vector.

    Optional parameter length can be used as abbreviation. v.normalize().mul(33) -> v.normalize(33);

    Parameters

    • Optional length: number

      [optional] length of the target vector. If not set, length is 1.0.

    Returns this

    Chainable

  • "angle of incidence equal to the angle of reflexion" Performs a simple reflection of this object on a surface that has the direction of the given vector u.

    Parameters

    Returns Vect

  • Rotates the vector by the given angle. If you take the vector as a point, the default pivot is {x:0,y:0}

    Parameters

    • angle: number

      in radians

    • Optional pivot: Vect

      [optional] default is {x:0,y:0}

    Returns this

    the rotated vector

    Chainable

  • Rotates the vector to the given angle.

    Parameters

    • angle: number

      in radians

    Returns this

    the rotated vector

    Chainable

  • Sets the coordinates of this Vect. (Without instantiating a new object)

    Parameters

    • x: number
    • y: number

    Returns Vect

  • Substracts a vector.

    Parameters

    Returns this

    Chainable

  • Returns this

    Chainable

  • Returns this

    Chainable

  • Returns string

  • Product of two vectors needed for the Gauss's area formula.

    Describes the doubled area of the shape that is enclosed by (this.x,0), (v.x,0), (v.x,v.y),(this.x,this.y). So its an area based on the x-axis. If you reflect it on the x-axis, you get the trapeze of which the area value is calculated.

    Needed for orientation and area of a polygon.

    Parameters

    Returns number

    See

    Polygon.prototype.getArea() //TODO

    Example

    const u = new Vect(3,5);
    const v = new Vect(5,7);
    const polygon = new Polygon(u, u.clone().mirrorOnX(), v.clone().mirrorOnY(), v);
    const result = u.trapeze(v);

    print(result);
    draw(u,v,polygon);
  • Returns this

    Chainable

  • Returns this

    Chainable

Generated using TypeDoc