SVG Graph Network API Documentation - v0.2.0
    Preparing search index...

    Class Vector

    Simple Vector class for physics calculations with full TypeScript support

    Index

    Constructors

    • Create a new Vector with x and y components

      Parameters

      • x: number = 0

        X component (default: 0)

      • y: number = 0

        Y component (default: 0)

      Returns Vector

    Properties

    x: number = 0

    X component (default: 0)

    y: number = 0

    Y component (default: 0)

    Methods

    • Subtract another vector from this vector

      Parameters

      Returns Vector

      New vector representing the difference

    • Multiply this vector by a scalar

      Parameters

      • s: number

        Scalar value to multiply by

      Returns Vector

      New vector representing the scaled vector

    • Divide this vector by a scalar

      Parameters

      • s: number

        Scalar value to divide by

      Returns Vector

      New vector representing the divided vector

      Error if dividing by zero

    • Calculate the magnitude (length) of this vector

      Returns number

      The magnitude of the vector

    • Normalize this vector to unit length

      Returns Vector

      New vector with magnitude 1 in the same direction

      Error if attempting to normalize a zero vector

    • Calculate the distance between two vectors

      Parameters

      Returns number

      Distance between the vectors

    • Create a vector from polar coordinates

      Parameters

      • magnitude: number

        Length of the vector

      • angle: number

        Angle in radians

      Returns Vector

      New vector from polar coordinates

    • Calculate the angle of this vector in radians

      Returns number

      Angle in radians (from -π to π)

    • Calculate the dot product with another vector

      Parameters

      Returns number

      Dot product result

    • Calculate the cross product magnitude with another vector (2D cross product)

      Parameters

      Returns number

      Cross product magnitude (scalar in 2D)

    • Check if this vector equals another vector (within tolerance)

      Parameters

      • v: Vector

        Other vector

      • tolerance: number = 1e-10

        Tolerance for comparison (default: 1e-10)

      Returns boolean

      True if vectors are equal within tolerance

    • Convert vector to string representation

      Returns string

      String representation of the vector

    • Convert vector to array [x, y]

      Returns [number, number]

      Array representation of the vector

    • Convert vector to object {x, y}

      Returns { x: number; y: number }

      Object representation of the vector