# Vector2D | data-structure-typed
Documentation for data-structure-typed

# Class Vector2D

#### Copyright

2030 Tyler Zeng zrwusa@gmail.com

#### License

MIT

#### Hierarchy

- Vector2D

- Defined in src/data-structures/matrix/vector2d.ts:5

#####
Index

### Constructors

constructor

### Properties

w
x
y

### Accessors

isZero
length
lengthSq
rounded

### Methods

zero
abs
add
angle
distance
distanceSq
divide
dot
equals
equalsRounded
multiply
normalize
perp
random
reverse
sign
subtract
subtractValue
truncate

## Constructors

### constructor

- new Vector2D(x?, y?, w?): Vector2D

- #### Parameters

  - ##### x: number = 0

  - ##### y: number = 0

  - ##### w: number = 1

  #### Returns Vector2D

  - Defined in src/data-structures/matrix/vector2d.ts:6

## Properties

### w

w: number = 1

- Defined in src/data-structures/matrix/vector2d.ts:9

### x

x: number = 0

- Defined in src/data-structures/matrix/vector2d.ts:7

### y

y: number = 0

- Defined in src/data-structures/matrix/vector2d.ts:8

## Accessors

### isZero

- get isZero(): boolean

- The function checks if the x and y values of a point are both zero.

  #### Returns boolean

  A boolean value indicating whether both the x and y properties of the object are equal to 0.

  - Defined in src/data-structures/matrix/vector2d.ts:17

### length

- get length(): number

- The above function calculates the length of a vector using the Pythagorean theorem.

  #### Returns number

  The length of a vector, calculated using the Pythagorean theorem.

  - Defined in src/data-structures/matrix/vector2d.ts:25

### lengthSq

- get lengthSq(): number

- The function calculates the square of the length of a vector.

  #### Returns number

  The method is returning the sum of the squares of the x and y values.

  - Defined in src/data-structures/matrix/vector2d.ts:33

### rounded

- get rounded(): Vector2D

- The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.

  #### Returns Vector2D

  The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest whole number.

  - Defined in src/data-structures/matrix/vector2d.ts:42

## Methods

### zero

- zero(): void

- The function sets the values of x and y to zero.

  #### Returns void

  - Defined in src/data-structures/matrix/vector2d.ts:307

### `Static` abs

- abs(vector): Vector2D

- The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x and y components.

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector, respectively.

  #### Returns Vector2D

  The method is returning a new Vector2D object with the absolute values of the x and y components of the input vector.

  - Defined in src/data-structures/matrix/vector2d.ts:200

### `Static` add

- add(vector1, vector2): Vector2D

- The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their x and y components.

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` is an instance of the `Vector2D` class. It represents a 2-dimensional vector with an `x` and `y` component.

  - ##### vector2: Vector2D

    The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with an x and y component.

  #### Returns Vector2D

  The method is returning a new instance of the Vector2D class with the x and y components of the two input vectors added together.

  - Defined in src/data-structures/matrix/vector2d.ts:56

### `Static` angle

- angle(vector): number

- The function calculates the angle between a given vector and the negative y-axis.

  #### Parameters

  - ##### vector: Vector2D

    The "vector" parameter is an instance of the Vector2D class, which represents a 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector, respectively.

  #### Returns number

  the angle between the given vector and the vector (0, -1) in radians.Returns the angle between origin and the given vector in radians

  - Defined in src/data-structures/matrix/vector2d.ts:285

### `Static` distance

- distance(vector1, vector2): number

- The function calculates the distance between two points in a two-dimensional space.

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` represents the first vector in 2D space, while `vector2` represents the second vector. Each vector has an `x` and `y` component, which represent their respective coordinates in the 2D space.

  - ##### vector2: Vector2D

    The `vector2` parameter represents the second vector in the calculation of distance. It is an instance of the `Vector2D` class, which typically has properties `x` and `y` representing the coordinates of the vector in a 2D space.

  #### Returns number

  The distance between vector1 and vector2.

  - Defined in src/data-structures/matrix/vector2d.ts:241

### `Static` distanceSq

- distanceSq(vector1, vector2): number

- The function calculates the squared distance between two 2D vectors.

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` represents the first vector, which is an instance of the `Vector2D` class. It contains the x and y coordinates of the vector.

  - ##### vector2: Vector2D

    The `vector2` parameter represents the second vector in a two-dimensional space. It has properties `x` and `y` which represent the coordinates of the vector.

  #### Returns number

  the square of the distance between the two input vectors.

  - Defined in src/data-structures/matrix/vector2d.ts:255

### `Static` divide

- divide(vector, value): Vector2D

- The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with x and y components.

  - ##### value: number

    The value parameter is a number that will be used to divide the x and y components of the vector.

  #### Returns Vector2D

  A new instance of the Vector2D class with the x and y values divided by the given value.

  - Defined in src/data-structures/matrix/vector2d.ts:108

### `Static` dot

- dot(vector1, vector2): number

- The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` represents a 2D vector with its x and y components.

  - ##### vector2: Vector2D

    The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector with an x and y component.

  #### Returns number

  The dot product of the two input vectors.

  - Defined in src/data-structures/matrix/vector2d.ts:211

### `Static` equals

- equals(vector1, vector2): boolean

- The function checks if two Vector2D objects are equal by comparing their x and y values.

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector. It has two properties: `x` and `y`, which represent the x and y components of the vector, respectively.

  - ##### vector2: Vector2D

    The parameter "vector2" is of type Vector2D.

  #### Returns boolean

  a boolean value, which indicates whether the two input vectors are equal or not.

  - Defined in src/data-structures/matrix/vector2d.ts:119

### `Static` equalsRounded

- equalsRounded(vector1, vector2, roundingFactor?): boolean

- The function checks if two Vector2D objects are equal within a specified rounding factor.

  #### Parameters

  - ##### vector1: Vector2D

    The first vector to compare.

  - ##### vector2: Vector2D

    The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector. It is used as one of the inputs for the "equalsRounded" function.

  - ##### `Optional` roundingFactor: number = 12

    The roundingFactor parameter is used to determine the threshold for considering two vectors as equal. If the absolute difference in the x and y components of the vectors is less than the roundingFactor, the vectors are considered equal.

  #### Returns boolean

  a boolean value.

  - Defined in src/data-structures/matrix/vector2d.ts:133

### `Static` multiply

- multiply(vector, value): Vector2D

- The function multiplies a Vector2D object by a given value.

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with x and y components.

  - ##### value: number

    The "value" parameter is a number that represents the value by which the x and y components of the vector will be multiplied.

  #### Returns Vector2D

  A new Vector2D object with the x and y values multiplied by the given value.

  - Defined in src/data-structures/matrix/vector2d.ts:96

### `Static` normalize

- normalize(vector): Vector2D

- The normalize function takes a vector as input and returns a normalized version of the vector.Normalizes the vector if it matches a certain condition

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D.

  #### Returns Vector2D

  the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the original vector.

  - Defined in src/data-structures/matrix/vector2d.ts:148

### `Static` perp

- perp(vector): Vector2D

- The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D.

  #### Returns Vector2D

  A new Vector2D object is being returned.

  - Defined in src/data-structures/matrix/vector2d.ts:178

### `Static` random

- random(maxX, maxY): Vector2D

- The function "random" generates a random Vector2D object with x and y values within the specified range.

  #### Parameters

  - ##### maxX: number

    The maxX parameter represents the maximum value for the x-coordinate of the random vector.

  - ##### maxY: number

    The `maxY` parameter represents the maximum value for the y-coordinate of the generated random vector.

  #### Returns Vector2D

  a new instance of the Vector2D class with random x and y values.

  - Defined in src/data-structures/matrix/vector2d.ts:298

### `Static` reverse

- reverse(vector): Vector2D

- The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector, respectively.

  #### Returns Vector2D

  A new Vector2D object with the negated x and y values of the input vector. Returns the vector that is the reverse of this vector

  - Defined in src/data-structures/matrix/vector2d.ts:188

### `Static` sign

- sign(vector1, vector2): number

- The sign function determines the sign of the cross product between two 2D vectors. (assuming the Y axis is pointing down, X axis to right like a Window app)

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` is of type `Vector2D`, which represents a 2-dimensional vector. It likely has properties `x` and `y` representing the x and y components of the vector, respectively.

  - ##### vector2: Vector2D

    The above code defines a function called "sign" that takes two parameters: vector1 and vector2. Both vector1 and vector2 are of type Vector2D.

  #### Returns number

  either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise

  - Defined in src/data-structures/matrix/vector2d.ts:270

### `Static` subtract

- subtract(vector1, vector2): Vector2D

- The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y components subtracted.

  #### Parameters

  - ##### vector1: Vector2D

    The parameter `vector1` is an instance of the `Vector2D` class, representing a 2-dimensional vector. It has properties `x` and `y` which represent the x and y components of the vector respectively.

  - ##### vector2: Vector2D

    The parameter "vector2" is a Vector2D object. It represents the second vector that you want to subtract from the first vector.

  #### Returns Vector2D

  The method is returning a new Vector2D object with the x and y components subtracted from vector1 and vector2.

  - Defined in src/data-structures/matrix/vector2d.ts:71

### `Static` subtractValue

- subtractValue(vector, value): Vector2D

- The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D object.

  #### Parameters

  - ##### vector: Vector2D

    The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with x and y components.

  - ##### value: number

    The "value" parameter is a number that will be subtracted from both the x and y components of the "vector" parameter.

  #### Returns Vector2D

  A new Vector2D object with the x and y values subtracted by the given value.

  - Defined in src/data-structures/matrix/vector2d.ts:84

### `Static` truncate

- truncate(vector, max): Vector2D

- The function truncates a vector to a maximum length if it exceeds that length.Adjusts x and y so that the length of the vector does not exceed max

  #### Parameters

  - ##### vector: Vector2D

    A 2D vector represented by the Vector2D class.

  - ##### max: number

    The `max` parameter is a number that represents the maximum length that the `vector` should have.

  #### Returns Vector2D

  either the original vector or a truncated version of the vector, depending on whether the length of the vector is greater than the maximum value specified.

  - Defined in src/data-structures/matrix/vector2d.ts:165

Generated using TypeDoc