Class: Vector2
WebSG.Vector2
A 2-dimensional vector.
Indexable
▪ [index: number
]: number
Table of contents
Constructors
Properties
Methods
- add
- addScaledVector
- addVectors
- divide
- divideScalar
- divideVectors
- multiply
- multiplyScalar
- multiplyVectors
- set
- setScalar
- subtract
- subtractScaledVector
- subtractVectors
Constructors
constructor
• new Vector2()
Constructs a new vector.
Defined in
• new Vector2(x
, y
)
Constructs a new vector with the given components.
Parameters
Name | Type | Description |
---|---|---|
x | number | The x component. |
y | number | The y component. |
Defined in
• new Vector2(array
)
Constructs and sets the initial components of the vector from a numeric array-like object.
Parameters
Name | Type |
---|---|
array | ArrayLike <number > |
Defined in
Properties
length
• Readonly
length: number
Returns the number of components in this vector.
Defined in
x
• x: number
The x component of the vector.
Defined in
y
• y: number
The y component of the vector.
Defined in
Methods
add
▸ add(vector
): Vector2
Adds the given vector to this vector.
Parameters
Name | Type | Description |
---|---|---|
vector | ArrayLike <number > | The vector to add. |
Returns
Defined in
addScaledVector
▸ addScaledVector(vector
, scale
): Vector2
Adds the given vector scaled by the given scalar to this vector.
Parameters
Name | Type |
---|---|
vector | ArrayLike <number > |
scale | number |
Returns
Defined in
addVectors
▸ addVectors(a
, b
): Vector2
Adds the given vectors together and stores the result in this vector.
Parameters
Name | Type | Description |
---|---|---|
a | ArrayLike <number > | The first vector. |
b | ArrayLike <number > | The second vector. |
Returns
Defined in
divide
▸ divide(vector
): Vector2
Divides this vector by the given vector.
Parameters
Name | Type | Description |
---|---|---|
vector | ArrayLike <number > | The vector to divide by. |
Returns
Defined in
divideScalar
▸ divideScalar(scalar
): Vector2
Divides this vector by the given scalar.
Parameters
Name | Type | Description |
---|---|---|
scalar | number | The scalar to divide by. |
Returns
Defined in
divideVectors
▸ divideVectors(a
, b
): Vector2
Divides the given vectors and stores the result in this vector.
Parameters
Name | Type | Description |
---|---|---|
a | ArrayLike <number > | The first vector. |
b | ArrayLike <number > | The second vector. |
Returns
Defined in
multiply
▸ multiply(vector
): Vector2
Multiplies this vector by the given vector.
Parameters
Name | Type | Description |
---|---|---|
vector | ArrayLike <number > | The vector to multiply by. |
Returns
Defined in
multiplyScalar
▸ multiplyScalar(scalar
): Vector2
Multiplies this vector by the given scalar.
Parameters
Name | Type | Description |
---|---|---|
scalar | number | The scalar to multiply by. |
Returns
Defined in
multiplyVectors
▸ multiplyVectors(a
, b
): Vector2
Multiplies the given vectors together and stores the result in this vector.
Parameters
Name | Type | Description |
---|---|---|
a | ArrayLike <number > | The first vector. |
b | ArrayLike <number > | The second vector. |
Returns
Defined in
set
▸ set(value
): Vector2
Sets the components of the vector.
Parameters
Name | Type | Description |
---|---|---|
value | ArrayLike <number > | The x,y components of the vector. |
Returns
Defined in
setScalar
▸ setScalar(value
): Vector2
Sets the components of the vector to a scalar value.
Parameters
Name | Type |
---|---|
value | number |
Returns
Defined in
subtract
▸ subtract(vector
): Vector2
Subtracts the given vector from this vector.
Parameters
Name | Type | Description |
---|---|---|
vector | ArrayLike <number > | The vector to subtract. |
Returns
Defined in
subtractScaledVector
▸ subtractScaledVector(vector
, scale
): Vector2
Subtracts the given vector scaled by the given scalar from this vector.
Parameters
Name | Type | Description |
---|---|---|
vector | ArrayLike <number > | The vector to subtract. |
scale | number | The scalar to scale the vector by. |
Returns
Defined in
subtractVectors
▸ subtractVectors(a
, b
): Vector2
Subtracts the second vector from the first and stores the result in this vector.
Parameters
Name | Type | Description |
---|---|---|
a | ArrayLike <number > | The first vector. |
b | ArrayLike <number > | The second vector. |