# Vector

Class representing a vector

## Constructor

#### new Vector(ps, pe)

Vector may be constructed by two points, or by two float numbers, or by array of two numbers

Source:
  - classes/vector.js, line 13

##### Parameters:

Name | Type | Description
--- | --- | ---
`ps` | `Point` | start point
`pe` | `Point` | end point

### Classes

Vector

### Members

#### length

Length of vector

Source:
  - classes/vector.js, line 96

#### slope

Slope of the vector in radians from 0 to 2PI

Source:
  - classes/vector.js, line 86

#### x :number

x-coordinate of a vector (float number)

Source:
  - classes/vector.js, line 25

##### Type:

- `number`

#### y :number

y-coordinate of a vector (float number)

Source:
  - classes/vector.js, line 30

##### Type:

- `number`

### Methods

#### add(v) → {Vector}

Return result of addition of other vector to this vector as a new vector

Source:
  - classes/vector.js, line 193

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` | Other vector

##### Returns:

Type:
  `Vector`

#### angleTo(v) → {number}

Return angle between this vector and other vector.
Angle is measured from 0 to 2*PI in the counter clockwise direction from current vector to other.

Source:
  - classes/vector.js, line 213

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` | Another vector

##### Returns:

Type:
  `number`

#### clone() → {Vector}

Method clone returns new instance of Vector

Source:
  - classes/vector.js, line 78

##### Returns:

Type:
  `Vector`

#### cross(v) → {number}

Returns vector product (cross product) of two vectors
`cross_product = (this x v)`

Source:
  - classes/vector.js, line 135

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` | Other vector

##### Returns:

Type:
  `number`

#### dot(v) → {number}

Returns scalar product (dot product) of two vectors
`dot_product = (this * v)`

Source:
  - classes/vector.js, line 125

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` | Other vector

##### Returns:

Type:
  `number`

#### equalTo(v) → {boolean}

Returns true if vectors are equal up to DP_TOL tolerance

Source:
  - classes/vector.js, line 106

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` |

##### Returns:

Type:
  `boolean`

#### invert() → {Vector}

Return inverted vector

Source:
  - classes/vector.js, line 184

##### Returns:

Type:
  `Vector`

#### multiply(scalar) → {Vector}

Returns new vector multiplied by scalar

Source:
  - classes/vector.js, line 115

##### Parameters:

Name | Type | Description
--- | --- | ---
`scalar` | `number` |

##### Returns:

Type:
  `Vector`

#### normalize() → {Vector}

Returns unit vector.
Throw error if given vector has zero length

Source:
  - classes/vector.js, line 144

##### Returns:

Type:
  `Vector`

#### projectionOn(v) → {Vector}

Return vector projection of the current vector on another vector

Source:
  - classes/vector.js, line 226

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` | Another vector

##### Returns:

Type:
  `Vector`

#### rotate(angle) → {Vector}

Returns new vector rotated by given angle, positive angle defines rotation in counter clockwise direction, negative - in clockwise direction

Source:
  - classes/vector.js, line 158

##### Parameters:

Name | Type | Description
--- | --- | ---
`angle` | `number` | Angle in radians

##### Returns:

Type:
  `Vector`

#### rotate90CCW() → {Vector}

Returns vector rotated 90 degrees counter clockwise

Source:
  - classes/vector.js, line 168

##### Returns:

Type:
  `Vector`

#### rotate90CW() → {Vector}

Returns vector rotated 90 degrees clockwise

Source:
  - classes/vector.js, line 176

##### Returns:

Type:
  `Vector`

#### subtract(v) → {Vector}

Return result of subtraction of other vector from current vector as a new vector

Source:
  - classes/vector.js, line 202

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | `Vector` | Another vector

##### Returns:

Type:
  `Vector`

#### toJSON() → {Object}

This method returns an object that defines how data will be serialized when called JSON.stringify() method

Source:
  - classes/vector.js, line 237

##### Returns:

Type:
  `Object`