ProtoTwin API
    Preparing search index...

    Class Vec2

    Immutable 2D vector.

    Implements

    Index

    Constructors

    • Constructor.

      Parameters

      • x: number

        The x component.

      • y: number

        The y component.

      Returns Vec2

    Properties

    x: number

    The x component of the vector.

    y: number

    The y component of the vector.

    nx: Vec2 = ...

    The negative x-axis vector.

    ny: Vec2 = ...

    The negative y-axis vector.

    one: Vec2 = ...

    The vector with all components set to one.

    x: Vec2 = ...

    The x-axis vector.

    y: Vec2 = ...

    The y-axis vector.

    zero: Vec2 = ...

    The zero vector.

    Methods

    • Adds two vectors.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns Vec2

      The sum of the two vectors.

    • Calculates the shortest unsigned angle between two vectors.

      Parameters

      • v1: IVec2

        The first vector.

      • v2: IVec2

        The second vector.

      Returns number

      The shortest unsigned angle (radians).

      The vectors must have non-zero lengths.

    • Calculates the shortest unsigned angle between two unit vectors.

      Parameters

      • n1: IVec2

        The first unit vector.

      • n2: IVec2

        The second unit vector.

      Returns number

      The shortest unsigned angle (radians).

    • The cross (scalar) product of two vectors.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns number

      The cross product.

    • Calculates the unit direction vector from the start point to the end point.

      Parameters

      • start: IVec2

        The start point.

      • end: IVec2

        The end point.

      Returns Vec2

      The unit direction vector.

      The start and end points must not be coincident.

    • Calculates the Euclidean distance between two points.

      Parameters

      • p1: IVec2

        The first point.

      • p2: IVec2

        The second point.

      Returns number

      The distance.

    • Calculates the square of the Euclidean distance between two points.

      Parameters

      • p1: IVec2

        The first point.

      • p2: IVec2

        The second point.

      Returns number

      The square of the distance.

    • Calculates the dot (scalar) product of two vectors.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns number

      The dot product.

    • Determines whether two vectors are exactly equal.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns boolean

      True if the two vectors are exactly equal, false otherwise.

    • Divides the first vector by the second vector component-wise.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns Vec2

      The component-wise division of the first vector by the second vector.

    • Linearly interpolates between two vectors.

      Parameters

      • lhs: IVec2

        The start vector.

      • rhs: IVec2

        The end vector.

      • weight: number

        The interpolation fraction between the two vectors.

      Returns Vec2

      The interpolated vector.

    • Calculates the mid point between the two points.

      Parameters

      • first: IVec2

        The first point.

      • second: IVec2

        The second point.

      Returns Vec2

      The mid point.

    • Negates the vector.

      Parameters

      Returns Vec2

      The negated vector.

    • The magnitude of the vector.

      Parameters

      Returns number

      The length of the vector.

    • Normalizes a vector.

      Parameters

      Returns Vec2

      The unit vector with the same direction.

      The vector must have non-zero length.

    • The square of the magnitude of the vector.

      Parameters

      Returns number

      The length squared of the vector.

    • Determines whether two vectors are not exactly equal.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns boolean

      True if the two vectors are different, false otherwise.

    • Finds a vector orthonormal to the specified unit vector.

      Parameters

      • n: IVec2

        The unit vector.

      Returns Vec2

      The orthonormal vector.

      The specified vector must have non-zero length.

    • Makes the second supplied unit vector orthonormal to the first supplied unit vector.

      Parameters

      • n1: Vec2

        The first unit vector.

      • n2: Vec2

        The second unit vector.

      Returns Vec2

      The orthonormalized second unit vector.

      Uses the Gram-Schmidt process.

    • Determines whether two vectors are (anti-)parallel.

      Parameters

      • v1: IVec2

        The first vector.

      • v2: IVec2

        The second vector.

      • eps: number = 0.000175

        The angular tolerance (radians).

      Returns boolean

      True if the vectors are (anti-)parallel, false otherwise.

      The two vectors are (anti-)parallel if the shortest angle between them is less than the specified tolerance.

    • Determines whether two unit vectors are (anti-)parallel.

      Parameters

      • n1: IVec2

        The first unit vector.

      • n2: IVec2

        The second unit vector.

      • eps: number = 0.000175

        The angular tolerance (radians).

      Returns boolean

      True if the unit vectors are (anti-)parallel, false otherwise.

      The two unit vectors are (anti-)parallel if the shortest angle between them is less than the specified tolerance.

    • Creates a random unit vector.

      Returns Vec2

      The random unit vector.

    • Multiplies the two vectors component-wise.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns Vec2

      The component-wise product of the two vectors.

    • Scales a vector uniformly.

      Parameters

      • lhs: IVec2

        The vector.

      • rhs: number

        The uniform scale factor.

      Returns Vec2

      The scaled vector.

    • Subtracts the second vector from the first vector.

      Parameters

      • lhs: IVec2

        The first vector.

      • rhs: IVec2

        The second vector.

      Returns Vec2

      The subtraction of the second vector from the first vector.