Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a 2D vector with single-precision.

author

RGreenlees

author

Kai Burjack

author

F. Neurath

Hierarchy

  • Vector2

Index

Constructors

constructor

  • Create a new Vector2 and initialize its components to zero.

    Returns Vector2

  • Create a new Vector2 and initialize both of its components with the given value.

    Parameters

    • d: number
         the value of both components
      

    Returns Vector2

  • Create a new Vector2 and initialize its components to the given values.

    Parameters

    • x: number
         the x component
      
    • y: number
         the y component
      

    Returns Vector2

  • Create a new Vector2 and initialize its components to the one of the given vector.

    Parameters

    • v: Vector2Like
         the {@link Vector2c} to copy the values from
      

    Returns Vector2

Properties

x

x: number

The x component of the vector.

y

y: number

The y component of the vector.

Methods

absolute

add

angle

ceil

clone

distance

  • distance(v: Vector2): number
  • distance(x: number, y: number): number
  • Get the length of a 2-dimensional single-precision vector.

    author

    F. Neurath

    Parameters

    Returns number

    the length of the given vector

  • Parameters

    • x: number
    • y: number

    Returns number

distanceSquared

  • distanceSquared(v: Vector2): number
  • distanceSquared(x: number, y: number): number

div

  • Divide this Vector2 component-wise by another Vector2c.

    Parameters

    Returns Vector2

    this

  • Divide all components of this Vector2 by the given scalar value.

    Parameters

    • scalar: number
           the scalar to divide by
      
    • Optional dest: Vector2

    Returns Vector2

    this

  • Divide the components of this Vector2 by the given scalar values and store the result in this.

    Parameters

    • x: number
           the x component to divide this vector by
      
    • y: number
           the y component to divide this vector by
      
    • Optional dest: Vector2

    Returns Vector2

    this

dot

equals

  • equals(v: Vector2, delta?: number): boolean
  • equals(x: number, y: number): boolean

floor

  • Set each component of this vector to the largest (to: closest positive infinity) {@code number} value that is less than or equal to that component and is equal to a mathematical integer.

    Parameters

    Returns Vector2

    this

fma

  • Add the component-wise multiplication of a * b to this vector.

    Parameters

    Returns Vector2

    this

  • Add the component-wise multiplication of a * b to this vector.

    Parameters

    • a: number
           the first multiplicand
      
    • b: Vector2
           the second multiplicand
      
    • Optional dest: Vector2

    Returns Vector2

    this

get

isFinite

  • isFinite(): boolean

length

  • length(): number

lengthSquared

  • lengthSquared(): number

lerp

  • Linearly interpolate this and other using the given interpolation factor t and store the result in this.

    If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

    Parameters

    • other: Vector2
           the other vector
      
    • t: number
           the interpolation factor between 0.0 and 1.0
      
    • Optional dest: Vector2

    Returns Vector2

    this

max

  • Set the components of this vector to be the component-wise maximum of this and the other vector.

    Parameters

    Returns Vector2

    this

maxComponent

  • maxComponent(): number

min

  • Set the components of this vector to be the component-wise minimum of this and the other vector.

    Parameters

    Returns Vector2

    this

minComponent

  • minComponent(): number

mul

  • Multiply the components of this vector by the given scalar.

    Parameters

    • scalar: number
         the value to multiply this vector's components by
      
    • Optional dest: Vector2

    Returns Vector2

    this

  • Multiply the components of this Vector2 by the given scalar values and store the result in this.

    Parameters

    • x: number
           the x component to multiply this vector by
      
    • y: number
           the y component to multiply this vector by
      
    • Optional dest: Vector2

    Returns Vector2

    this

  • Multiply this Vector2 component-wise by another Vector2.

    Parameters

    Returns Vector2

    this

  • Multiply the given matrix with this Vector2 and store the result in this.

    Parameters

    Returns Vector2

    this

mulDirection

  • Multiply the given 3x2 matrix mat with this.

    This method assumes the z component of this to be 0.0.

    Parameters

    • mat: Matrix3
           the matrix to multiply this vector by
      
    • Optional dest: Vector2

    Returns Vector2

    this

mulPosition

  • Multiply the given 3x2 matrix mat with this.

    This method assumes the z component of this to be 1.0.

    Parameters

    • mat: Matrix3
           the matrix to multiply this vector by
      
    • Optional dest: Vector2

    Returns Vector2

    this

mulTranspose

negate

normalize

perpendicular

round

  • Set each component of this vector to the closest number that is equal to a mathematical integer, ties: with rounding to positive infinity.

    Parameters

    Returns Vector2

    this

set

setComponent

  • setComponent(component: number, value: number): Vector2
  • Set the value of the specified component of this vector.

    throws

    IllegalArgumentException if component is not within [0..1]

    Parameters

    • component: number
           the component whose value to set, : within<code>[0..1]</code>
      
    • value: number
           the value to set
      

    Returns Vector2

    this

sub

toString

  • toString(formatter?: (x: number, place: "x" | "y") => string): string
  • Return a string representation of this vector by formatting the vector components with the given {@link NumberFormat}.

    Parameters

    • Optional formatter: (x: number, place: "x" | "y") => string
           the {@link NumberFormat} used to format the vector components with
      
        • (x: number, place: "x" | "y"): string
        • Parameters

          • x: number
          • place: "x" | "y"

          Returns string

    Returns string

    the string representation

trunc

zero

Static distance

  • distance(x1: number, y1: number, x2: number, y2: number): number
  • Return the distance between (x1, y1) and (x2, y2).

    Parameters

    • x1: number
           the x component of the first vector
      
    • y1: number
           the y component of the first vector
      
    • x2: number
           the x component of the second vector
      
    • y2: number
           the y component of the second vector
      

    Returns number

    the euclidean distance

Static distanceSquared

  • distanceSquared(x1: number, y1: number, x2: number, y2: number): number
  • Return the squared distance between (x1, y1) and (x2, y2).

    Parameters

    • x1: number
           the x component of the first vector
      
    • y1: number
           the y component of the first vector
      
    • x2: number
           the x component of the second vector
      
    • y2: number
           the y component of the second vector
      

    Returns number

    the euclidean distance squared

Static lengthSquared

  • lengthSquared(x: number, y: number): number
  • Get the length squared of a 2-dimensional single-precision vector.

    author

    F. Neurath

    Parameters

    • x: number

      The vector's x component

    • y: number

      The vector's y component

    Returns number

    the length squared of the given vector

Generated using TypeDoc