Class: Vector2

Vector2

new Vector2(x, y)

二维向量

Name Type Default Description
x Number 0 optional

X component

y Number 0 optional

Y component

Members Show Inherited

Name Type Default Description
className String Vector2

类名

isVector2 Boolean true
elements Float32Array

数据

x Number

X component

y Number

Y component

Methods Show Inherited

Copy the values from one vec2 to this

Name Type Description
m Vector2

the source vector

Returns:
Type Description
Vector2 this

Creates a new vec2 initialized with values from this vector

Returns:
Type Description
Vector2 a new Vector2

toArray(array, offset){Array}

转换到数组

Name Type Default Description
array Array.<number> | TypedArray [] optional

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Array

fromArray(array, offset){Vector2}

从数组赋值

Name Type Default Description
array Array.<number> | TypedArray

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Vector2 this

Set the components of a vec4 to the given values

Name Type Description
x Number

X component

y Number

Y component

Returns:
Type Description
Vector2 this

Adds two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的和

Returns:
Type Description
Vector2 this

subtract(a, b){Vector2}

Subtracts vector b from vector a

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的差

Returns:
Type Description
Vector2 this

multiply(a, b){Vector2}

Multiplies two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的积

Returns:
Type Description
Vector2 this

Divides two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的商

Returns:
Type Description
Vector2 this

Math.ceil the components of this

Returns:
Type Description
Vector2 this

Math.floor the components of this

Returns:
Type Description
Vector2 this

Returns the minimum of two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Vector2 this

Returns the maximum of two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Vector2 this

Math.round the components of this

Returns:
Type Description
Vector2 this

Scales this by a scalar number

Name Type Description
scale Number

amount to scale the vector by

Returns:
Type Description
Vector2 this

scaleAndAdd(scale, a, b){Vector2}

Adds two vec2's after scaling the second vector by a scalar value

Name Type Description
scale Number

the amount to scale the second vector by before adding

a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Vector2 this

distance(a, b){Number}

Calculates the euclidian distance between two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Number distance between a and b

squaredDistance(a, b){Number}

Calculates the squared euclidian distance between two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Number squared distance between a and b

length(){Number}

Calculates the length of this

Returns:
Type Description
Number length of this

squaredLength(){Number}

Calculates the squared length of this

Returns:
Type Description
Number squared length of this

Negates the components of this

Returns:
Type Description
Vector2 this

Returns the inverse of the components of a vec2

Name Type Default Description
a Vector2 this optional
Returns:
Type Description
Vector2 this

Normalize this

Returns:
Type Description
Vector2 this

dot(a, b){Number}

Calculates the dot product of two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Number product of a and b

cross(a, b){Number}

Computes the cross product of two vec2's

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Number cross product of a and b

Performs a linear interpolation between two vec2's

Name Type Description
v Vector2
t Number

interpolation amount between the two vectors

Returns:
Type Description
Vector2 this

random(scale){Vector2}

Generates a random vector with the given scale

Name Type Default Description
scale Number 1 optional

Length of the resulting vector. If ommitted, a unit vector will be returned

Returns:
Type Description
Vector2 this

transformMat3(m){Vector2}

Transforms the vec2 with a mat3

Name Type Description
m Matrix3

matrix to transform with

Returns:
Type Description
Vector2 this

transformMat4(m){Vector2}

Transforms the vec2 with a mat4

Name Type Description
m Matrix4

matrix to transform with

Returns:
Type Description
Vector2 this

exactEquals(a, b){Boolean}

Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Boolean True if the vectors are equal, false otherwise.

equals(a, b){Boolean}

Returns whether or not the vectors have approximately the same elements in the same position.

Name Type Description
a Vector2
b Vector2 optional

如果不传,计算 this 和 a 的结果

Returns:
Type Description
Boolean True if the vectors are equal, false otherwise.

Alias for Vector2#subtract

Alias for Vector2#multiply

Alias for Vector2#divide

Alias for Vector2#distance

Alias for Vector2#length