Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Vector2

Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent a number of things, such as: A point in 2D space (i.e. a position on a plane). A direction and length across a plane. In three.js the length will always be the Euclidean distancee (straight-line distance) from (0, 0) to (x, y) and the direction is also measured from (0, 0) towards (x, y). Any arbitrary ordered pair of numbers. There are other things a 2D vector can be used to represent, such as momentum vectors, complex numbers and so on, however these are the most common uses in three.js. Iterating through a Vector2 instance will yield its components (x, y) in the corresponding order. See the ngx3js docs page for details.

Examples

css2d / label | misc / controls / drag | misc / controls / fly | misc / uv / tests | physics / ammo / break

Code Example

const a = new THREE.Vector2( 0, 1 );
// no arguments; will be initialised to (0, 0)
const b = new THREE.Vector2( );
const d = a.distanceTo( b );

Hierarchy

Index

Constructors

constructor

Properties

height

height: number

Alias for y

Readonly isVector2

isVector2: true

width

width: number

Alias for x

x

x: number

the x value of this vector. Default is 0

default

0

y

y: number

the y value of this vector. Default is 0.

default

0

Methods

add

addScalar

addScaledVector

addVectors

angle

  • angle(): number

applyMatrix3

ceil

clamp

  • If this vector's x or y value is less than the min vector's x or y value, it is replaced by the corresponding value.

    Parameters

    • min: I3JS.Vector2

      The minimum x and y values.

    • max: I3JS.Vector2

      The maximum x and y values in the desired range If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value.

    Returns I3JS.Vector2

clampLength

  • If this vector's length is less than the min value, it is replaced by the min value.

    Parameters

    • min: number

      The minimum value the length will be clamped to

    • max: number

      The maximum value the length will be clamped to If this vector's length is greater than the max value, it is replaced by the max value.

    Returns I3JS.Vector2

clampScalar

  • If this vector's x or y values are less than the min value, they are replaced by the min value.

    Parameters

    • min: number

      The minimum value the components will be clamped to

    • max: number

      The maximum value the components will be clamped to If this vector's x or y values are greater than the max value, they are replaced by the max value.

    Returns I3JS.Vector2

clone

copy

cross

  • Calculates the cross product of this vector and v. Note that a 'cross-product' in 2D is not well-defined. This function computes a geometric cross-product often used in 2D graphics

    [method:Boolean equals]( [param:Vector2 v] )

    Parameters

    Returns number

    Returns true if the components of this vector and v are strictly equal; false otherwise.

distanceTo

distanceToSquared

divide

divideScalar

dot

equals

floor

fromArray

  • fromArray(array: ArrayLike<number> | number[], offset?: number): I3JS.Vector2
  • Parameters

    • array: ArrayLike<number> | number[]

      array to store this vector to. If this is not provided, a new array will be created.

    • Optional offset: number

      optional offset into the array.

    Returns I3JS.Vector2

    Returns an array [x, y], or copies x and y into the provided array.

fromBufferAttribute

getComponent

  • getComponent(index: number): number

length

  • length(): number

lengthSq

  • lengthSq(): number

lerp

lerpVectors

manhattanDistanceTo

manhattanLength

  • manhattanLength(): number

max

min

multiply

multiplyScalar

negate

normalize

random

rotateAround

round

roundToZero

set

setComponent

  • setComponent(index: number, value: number): I3JS.Vector2

setLength

setScalar

setX

setY

sub

subScalar

subVectors

Generated using TypeDoc