Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/threejs_4_deno/src/Three.d.ts>Vector2

A simple transformation of three.js for use within a Deno workflow
Go to Latest
class Vector2
implements Vector
Re-export
import { Vector2 } from "https://deno.land/x/threejs_4_deno@v121/src/Three.d.ts";

2D vector.

( class Vector2 implements Vector )

Constructors

new
Vector2(x?: number, y?: number)

Properties

height: number
readonly
isVector2: true
width: number
x: number
y: number

Methods

add(v: Vector2, w?: Vector2): this

Adds v to this vector.

addScalar(s: number): this

Adds the scalar value s to this vector's x and y values.

addScaledVector(v: Vector2, s: number): this

Adds the multiple of v and s to this vector.

addVectors(a: Vector2, b: Vector2): this

Sets this vector to a + b.

angle(): number

computes the angle in radians with respect to the positive x-axis

Multiplies this vector (with an implicit 1 as the 3rd component) by m.

ceil(): this

The x and y components of the vector are rounded up to the nearest integer value.

clamp(min: Vector2, max: Vector2): this

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. 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.

clampLength(min: number, max: number): this

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

clampScalar(min: number, max: number): this

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

clone(): this

Returns a new Vector2 instance with the same x and y values.

copy(v: Vector2): this

Copies value of v to this vector.

cross(v: Vector2): number

Computes cross product of this vector and v.

distanceTo(v: Vector2): number

Computes distance of this vector to v.

deprecated
distanceToManhattan(v: Vector2): number

Computes squared distance of this vector to v.

divide(v: Vector2): this

Divides this vector by v.

divideScalar(s: number): this

Divides this vector by scalar s. Set vector to ( 0, 0 ) if s == 0.

dot(v: Vector2): number

Computes dot product of this vector and v.

equals(v: Vector2): boolean

Checks for strict equality of this vector and v.

floor(): this

The components of the vector are rounded down to the nearest integer value.

fromArray(array: number[], offset?: number): this

Sets this vector's x and y value from the provided array.

fromArray(array: ArrayLike<number>, offset?: number): this

Sets this vector's x and y value from the provided array-like.

fromBufferAttribute(attribute: BufferAttribute, index: number): this

Sets this vector's x and y values from the attribute.

getComponent(index: number): number

Gets a component of this vector.

length(): number

Computes length of this vector.

deprecated
lengthManhattan(): number
lengthSq(): number

Computes squared length of this vector.

lerp(v: Vector2, alpha: number): this

Linearly interpolates between this vector and v, where alpha is the distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.

lerpVectors(
v1: Vector2,
v2: Vector2,
alpha: number,
): this

Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the distance along the line connecting the two vectors - alpha = 0 will be v1, and alpha = 1 will be v2.

Computes the Manhattan length (distance) from this vector to the given vector v

manhattanLength(): number

Computes the Manhattan length of this vector.

max(v: Vector2): this

If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.

min(v: Vector2): this

If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.

multiply(v: Vector2): this

Multiplies this vector by v.

multiplyScalar(scalar: number): this

Multiplies this vector by scalar s.

negate(): this

Inverts this vector.

normalize(): this

Normalizes this vector.

random(): this

Sets this vector's x and y from Math.random

rotateAround(center: Vector2, angle: number): this

Rotates the vector around center by angle radians.

round(): this

The components of the vector are rounded to the nearest integer value.

roundToZero(): this

The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.

set(x: number, y: number): this

Sets value of this vector.

setComponent(index: number, value: number): this

Sets a component of this vector.

setLength(length: number): this

Normalizes this vector and multiplies it by l.

setScalar(scalar: number): this

Sets the x and y values of this vector both equal to scalar.

setX(x: number): this

Sets X component of this vector.

setY(y: number): this

Sets Y component of this vector.

sub(v: Vector2): this

Subtracts v from this vector.

subScalar(s: number): this

Subtracts s from this vector's x and y components.

subVectors(a: Vector2, b: Vector2): this

Sets this vector to a - b.

toArray(array?: number[], offset?: number): number[]

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

toArray(array: ArrayLike<number>, offset?: number): ArrayLike<number>

Copies x and y into the provided array-like.