bitbybit.dev v1.0.0-rc.1
    Preparing search index...

    Class Vector

    Index

    Constructors

    angles

    • Measures the angle between two vectors in degrees (always returns positive angle 0-180°). Example: [1,0,0] and [0,1,0] → 90° (perpendicular vectors)

      Parameters

      • inputs: TwoVectorsDto

        Contains two vectors represented as number arrays

      Returns number

      Number in degrees

      angle

      false

    • Measures the normalized 2D angle between two vectors in degrees (considers direction, can be negative). Example: [1,0] to [0,1] → 90°, [0,1] to [1,0] → -90°

      Parameters

      • inputs: TwoVectorsDto

        Contains two vectors represented as number arrays

      Returns number

      Number in degrees

      angle normalized 2d

      false

    • Measures a positive angle between two vectors given the reference vector in degrees (always 0-360°). Example: converts negative signed angles to positive by adding 360° when needed

      Parameters

      Returns number

      Number in degrees

      positive angle

      false

    • Computes signed angle between two vectors using a reference vector (determines rotation direction). Example: Returns positive or negative angle depending on rotation direction relative to reference

      Parameters

      Returns number

      Signed angle in degrees

      signed angle

      false

    base

    • Computes the cross product of two 3D vectors (perpendicular vector to both inputs). Example: [1,0,0] × [0,1,0] → [0,0,1] (right-hand rule)

      Parameters

      Returns number[]

      Crossed vector

      cross

      false

    • Divides each element of the vector by a scalar value. Example: [10,20,30] ÷ 2 → [5,10,15]

      Parameters

      Returns number[]

      Vector that is a result of division by a scalar

      div

      false

    • Computes the domain (range) between minimum and maximum values of the vector. Example: [1,3,5,9] → 8 (difference between last and first: 9-1)

      Parameters

      Returns number

      Number representing distance between two vectors

      domain

      false

    • Calculates the dot product between two vectors (measures similarity/projection). Example: [1,2,3] • [4,5,6] → 32 (1×4 + 2×5 + 3×6), perpendicular vectors → 0

      Parameters

      Returns number

      Number representing dot product of the vector

      dot

      false

    • Multiplies each element of the vector by a scalar value. Example: [2,3,4] × 5 → [10,15,20]

      Parameters

      Returns number[]

      Vector that results from multiplication

      mul

      false

    • Negates the vector (flips the sign of each element). Example: [5,-3,2] → [-5,3,-2]

      Parameters

      Returns number[]

      Negative vector

      neg

      false

    • Computes the squared norm (squared magnitude/length) of the vector. Example: [3,4,0] → 25 (length 5 squared)

      Parameters

      Returns number

      Number that is squared norm

      norm squared

      false

    • Calculates the norm (magnitude/length) of the vector. Example: [3,4,0] → 5, [1,0,0] → 1

      Parameters

      Returns number

      Number that is norm of the vector

      norm

      false

    • Normalizes the vector into a unit vector that has a length of 1 (maintains direction, scales magnitude to 1). Example: [3,4,0] → [0.6,0.8,0], [10,0,0] → [1,0,0]

      Parameters

      Returns number[]

      Unit vector that has length of 1

      normalized

      false

    • Finds a point on a ray at a given distance from the origin along the direction vector. Example: Point [0,0,0] + direction [1,0,0] at distance 5 → [5,0,0]

      Parameters

      • inputs: RayPointDto

        Provide a point, vector and a distance for finding a point

      Returns number[]

      Vector representing point on the ray

      on ray

      false

    • Subtracts the second vector from the first element-wise. Example: [10,20,30] - [1,2,3] → [9,18,27]

      Parameters

      Returns number[]

      Vector that result by subtraction two vectors

      sub

      false

    • Sums all values in the vector and returns a single number. Example: [1,2,3,4] → 10, [5,10,15] → 30

      Parameters

      Returns number

      Number that results by adding up all values in the vector

      sum

      false

    • Computes the squared length (squared magnitude) of a 3D vector. Example: [3,4,0] → 25 (length 5 squared)

      Parameters

      Returns number

      Number that is squared length of the vector

      length squared

      false

    • Computes the length (magnitude) of a 3D vector. Example: [3,4,0] → 5, [1,0,0] → 1

      Parameters

      Returns number

      Number that is length of the vector

      length

      false

    create

    • Creates a 3D vector from x, y, z coordinates. Example: x=1, y=2, z=3 → [1,2,3]

      Parameters

      Returns Vector3

      Create a vector of xyz values

      vector XYZ

      true

    • Creates a 2D vector from x, y coordinates. Example: x=3, y=4 → [3,4]

      Parameters

      Returns Vector2

      Create a vector of xy values

      vector XY

      true

    • Creates a vector of integers from 0 to max (exclusive). Example: max=5 → [0,1,2,3,4], max=3 → [0,1,2]

      Parameters

      Returns number[]

      Vector containing items from 0 to max

      range

      false

    • Creates a vector containing numbers from min to max at a given step increment. Example: min=0, max=10, step=2 → [0,2,4,6,8,10]

      Parameters

      • inputs: SpanDto

        Span information containing min, max and step values

      Returns number[]

      Vector containing number between min, max and increasing at a given step

      span

      false

    • Creates a vector with numbers from min to max using an easing function for non-linear distribution. Example: min=0, max=100, nrItems=5, ease='easeInQuad' → creates accelerating intervals

      Parameters

      Returns number[]

      Vector containing numbers between min, max and increasing in non-linear steps defined by nr of items in the vector and type

      span ease items

      false

    • Creates a vector with evenly spaced numbers from min to max with a specified number of items. Example: min=0, max=10, nrItems=5 → [0, 2.5, 5, 7.5, 10]

      Parameters

      Returns number[]

      Vector containing number between min, max by giving nr of items

      span linear items

      false

    • Converts an array of stringified numbers to actual numbers. Example: ['1', '2.5', '3'] → [1, 2.5, 3], ['10', '-5', '0.1'] → [10, -5, 0.1]

      Parameters

      Returns number[]

      Array of numbers

      parse numbers

      false

    distance

    • Calculates squared distance between two vectors (faster than distance, avoids sqrt). Example: [0,0,0] to [3,4,0] → 25 (distance 5 squared)

      Parameters

      Returns number

      Number representing squared distance between two vectors

      dist squared

      false

    • Calculates the Euclidean distance between two vectors. Example: [0,0,0] to [3,4,0] → 5, [1,1] to [4,5] → 5

      Parameters

      Returns number

      Number representing distance between two vectors

      dist

      false

    • Finds an interpolated vector between two vectors using a fraction (linear interpolation). Example: [0,0,0] to [10,10,10] at 0.5 → [5,5,5], fraction="/?originalUrl=https%3A%2F%2Fdocs.bitbybit.dev%2F0%2520%25E2%2586%2592%2520first%2C%2520fraction%3D1%2520%25E2%2586%2592%2520second%253C%2Fp">

      Parameters

      Returns number[]

      Vector that is in between two vectors

      lerp

      false

    extract

    • Finds the maximum (largest) value in the vector. Example: [3, 7, 2, 9, 1] → 9

      Parameters

      Returns number

      Largest number in the vector

      max

      false

    • Finds the minimum (smallest) value in the vector. Example: [3, 7, 2, 9, 1] → 1

      Parameters

      Returns number

      Lowest number in the vector

      min

      false

    remove

    • Removes all duplicate vectors from the input array (keeps only unique vectors). Example: [[1,2,3], [4,5,6], [1,2,3], [7,8,9]] → [[1,2,3], [4,5,6], [7,8,9]]

      Parameters

      Returns number[][]

      Array of vectors without duplicates

      remove all duplicates

      false

    • Removes consecutive duplicate vectors from the input array (only removes duplicates that appear next to each other). Example: [[1,2], [1,2], [3,4], [1,2]] → [[1,2], [3,4], [1,2]] (only removed consecutive duplicate)

      Parameters

      Returns number[][]

      Array of vectors without duplicates

      remove consecutive duplicates

      false

    sum

    • Adds all vector xyz values together element-wise and creates a new vector. Example: [[1,2,3], [4,5,6], [7,8,9]] → [12,15,18] (sums each column)

      Parameters

      Returns number[]

      New vector that has xyz values as sums of all the vectors

      add all

      false

    • Adds two vectors together element-wise. Example: [1,2,3] + [4,5,6] → [5,7,9]

      Parameters

      Returns number[]

      Number array representing vector

      add

      false

    • Checks if the boolean array contains only true values, returns false if there's a single false. Example: [true, true, true] → true, [true, false, true] → false

      Parameters

      Returns boolean

      Boolean indicating if vector contains only true values

      all

      false

    validate

    • Checks if two vectors are the same within a given tolerance (accounts for floating point precision). Example: [1,2,3] vs [1.0001,2.0001,3.0001] with tolerance 0.001 → true

      Parameters

      Returns boolean

      Boolean indicating if vectors are the same

      vectors the same

      false

    • Checks if each element in the vector is finite and returns a boolean array. Example: [1, 2, Infinity, 3] → [true, true, false, true]

      Parameters

      • inputs: VectorDto

        Vector with possibly infinite values

      Returns boolean[]

      Vector array that contains boolean values for each number in the input vector that identifies if value is finite (true) or infinite (false)

      finite

      false

    • Checks if the vector has zero length (all elements are zero). Example: [0,0,0] → true, [0,0,0.001] → false

      Parameters

      Returns boolean

      Boolean that identifies if vector is zero length

      isZero

      false