Vector2
Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y).
Implements
- Vector
Constructors
constructor
Parameters
- _x: number
- _y: number
Returns Vector2
Properties
x0
the x value of this vector.
y0
the y value of this vector.
is Vector2
Check the type whether it belongs to Vector2. This value should not be changed by user.
Accessors
width
- get width(): number
Same to x.
Returns number
- set width(w: number): void
Parameters
- w: number
Returns void
height
- get height(): number
Same to y.
Returns number
- set height(h: number): void
Parameters
- h: number
Returns void
Methods
set
set Scalar
set X
set Y
set Component
get Component
clone
clone Readonly
- cloneReadonly(): Readonly<
Pick<
ReadonlyMarked,
| "_readonly_mark"
| "cloneReadonly"
| "clone"
| "equals"
| "getSerializeData"
| "x"
| "y"
| "getNumberCount"
| "toArray"
| "width"
| "height"
| "isVector2"
| "dot"
| "cross"
| "lengthSq"
| "length"
| "angle"
| "manhattanLength"
| "distanceTo"
| "distanceToSquared"
| "manhattanDistanceTo"
| "intoSize",
>,
>Returns Readonly<
Pick<
ReadonlyMarked,
| "_readonly_mark"
| "cloneReadonly"
| "clone"
| "equals"
| "getSerializeData"
| "x"
| "y"
| "getNumberCount"
| "toArray"
| "width"
| "height"
| "isVector2"
| "dot"
| "cross"
| "lengthSq"
| "length"
| "angle"
| "manhattanLength"
| "distanceTo"
| "distanceToSquared"
| "manhattanDistanceTo"
| "intoSize",
>,
>
copy
add
add Scalar
add Vectors
add Scaled Vector
sub
sub Scalar
sub Vectors
multiply
multiply Scalar
Multiplies this vector by scalar s.
Parameters
- scalar: number
Returns Vector2
Implementation of Vector.multiplyScalar
divide
divide Scalar
Divides this vector by scalar s.
Sets vector to( 0, 0 )if s = 0.Parameters
- scalar: number
Returns Vector2
Implementation of Vector.divideScalar
apply Matrix3
apply Matrix4
min
max
clamp
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.Parameters
Returns Vector2
clamp Scalar
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.Parameters
- minVal: number
- maxVal: number
Returns Vector2
clamp Length
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.Parameters
- min: number
the minimum value the length will be clamped to.
- max: number
the maximum value the length will be clamped to.
Returns Vector2
- min: number
floor
The components of this vector are rounded down to the nearest integer value.
Returns Vector2
ceil
round
The components of this vector are rounded to the nearest integer value.
Returns Vector2
round To Zero
The components of this vector are rounded towards zero (up if negative, down if positive) to an integer value.
Returns Vector2
negate
dot
Calculates the dot product of this vector and v.
Parameters
- v: Vector2
Returns number
Implementation of Vector.dot
cross
length Sq
Computes the square of the Euclidean length (straight-line length) from (0, 0) to (x, y). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
Returns number
Implementation of Vector.lengthSq
length
Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).
Returns number
Implementation of Vector.length
manhattan Length
Computes the Manhattan length of this vector.
Returns number
normalize
Converts this vector to a unit vector. that is, sets it equal to a vector with the same direction as this one, but length| length 1.
Returns Vector2
Implementation of Vector.normalize
angle
Computes the angle in radians of this vector with respect to the positive x-axis.
Returns number
distance To
distance To Squared
manhattan Distance To
set Length
Sets this vector to a vector with given length the same direction as this one.
Parameters
- length: number
Returns Vector2
Implementation of Vector.setLength
lerp
lerp Vectors
equals
from Arrayis 0.
get Number Count
There are 2 elements in this vector.
Returns number
to Array
Returns an array [x, y], or copies x and y into the provided array.
Parameters
- array: number[]
(optional) array to store this vector to. If this is not provided, a new array will be created.
- offset: number
(optional) optional offset into the array.
Returns number[]
Implementation of Vector.toArray
- array: number[]
from Buffer Attribute
- fromBufferAttribute(
attribute: {
getX: (number: number) => number;
getY: (number: number) => number;
},
index: number,
offset?: number,
): Vector2Parameters
- attribute: { getX: (number: number) => number; getY: (number: number) => number }
the source attribute.
- index: number
index in the attribute.
- offset: number
Returns Vector2
- attribute: { getX: (number: number) => number; getY: (number: number) => number }
rotate Around
into Size
Returns Size
Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y).