Class Vector2d

a generic 2D Vector Object

Constructors

constructor

Properties

x

x: number

y

y: number

Methods

abs

add

angle

ceil

ceilSelf

clamp

clampSelf

clone

copy

cross

distance

  • distance(v): number
  • Calculates the Euclidean distance between this vector and another vector.

    Parameters

    • v: Vector2d

      The vector to which the distance is calculated.

    Returns number

    The Euclidean distance between this vector and the given vector.

    Example

    letv1 = newVector2d(3, 4);
    letv2 = newVector2d(6, 8);
    v1.distance(v2); // returns 5

div

dot

equals

  • equals(...args): boolean
  • Checks if this vector is equal to another vector or a pair of coordinates.

    Parameters

    • Rest...args: [number, number] | [XYPoint | Vector2d ]

      Either two numbers representing x and y coordinates or a single Vector2d object.

    Returns boolean

    True if the coordinates are equal, false otherwise.

    Example

    letv1 = newVector2d(3, 4);
    letv2 = newVector2d(3, 4);
    v1.equals(v2); // returns true

    Example

    letv = newVector2d(3, 4);
    v.equals(3, 4); // returns true

floor

floorSelf

length

length2

lerp

  • lerp(v, alpha): Vector2d
  • Linearly interpolate between this vector and the given one.

    Parameters

    • v: Vector2d

      other vector

    • alpha: number

      distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).

    Returns Vector2d

    Reference to this object for method chaining

maxV

minV

moveTowards

  • moveTowards(target, step): Vector2d
  • interpolate the position of this vector towards the given one by the given maximum step.

    Parameters

    • target: Vector2d

      vector to rotate towards

    • step: number

      the maximum step per iteration (Negative values will push the vector away from the target)

    Returns Vector2d

    Reference to this object for method chaining

negate

negateSelf

normalize

perp

project

projectN

rotate

  • rotate(angle, v?): Vector2d
  • Rotate this vector (counter-clockwise) by the specified angle (in radians).

    Parameters

    • angle: number

      The angle to rotate (in radians)

    • Optionalv: XYPoint

      an optional point to rotate around

    Returns Vector2d

    Reference to this object for method chaining

scale

  • scale(x, y?): Vector2d
  • Multiply this vector values by the given scalar

    Parameters

    • x: number

      x scale value

    • Optionaly: number = x

      y scale value, if not passed, it uses the x value

    Returns Vector2d

    Reference to this object for method chaining

scaleV

set

setV

setZero

sub

to2d

toIso

toString

  • toString(): `x:${number},y:${number}`
  • convert the object to a string representation

    Returns `x:${number},y:${number}`

    stringified representation of this vector

Settings

Member Visibility

On This Page

AltStyle によって変換されたページ (->オリジナル) /