Class: Vector

PhSim. Vector


new Vector(x, y)

Constructor for the minimal requirements for being a Vector.

Parameters:
Name Type Description
x Number
y Number
Source:

Members


x :Number

x-coordinate of the vector

Type:
  • Number
Source:

y :Number

y-coordinate of the vector

Type:
  • Number
Source:

Methods


<static> add(vector1, vector2 [, newObj])

Perform vector addition

Parameters:
Name Type Argument Default Description
vector1 Vector

The first vector

vector2 Vector

The second vector

newObj Boolean <optional>
true

Boolean that determines the return value. If true, then it returns a new Vector object vector such that vector.x === vector1.x + vector2.x and vector.x === vector1.y + vector2.y

If false, then vector2.x is added to vector1.x, vector2.y is added to vector1.y and then vector1 is returned.

Source:
Returns:
  • The sum of the two vectors. New object if newObj is true. Returns vector1 otherwise.
Type
Vector

<static> applyTransformation(a11, a12, a21, a22, x, y)

Apply a linear transformation defined by a 2x2 matrix to a vector.

Parameters:
Name Type Description
a11 Number

Element found in row 1, column 1

a12 Number

Element found in row 1, column 2

a21 Number

Element found in row 2, column 1

a22 Number

Element found in row 2, column 2

x Number

x-coordinate of vector to be transformed

y Number

y-coordinate of vector to be transformed

Source:
Returns:
  • The transformed vector

<static> distance(vector1, vector2)

Get distance between two vectors.

Parameters:
Name Type Description
vector1 Vector
vector2 Vector
Source:
Returns:
  • The vector distance

<static> divide(vector, scalar)

Divide a vector by a scalar

Parameters:
Name Type Description
vector Vector
scalar Number
Source:
Returns:
Type
Vector

<static> dotProduct(vector1, vector2)

Calculate dot product of vector1 and vector2.

Parameters:
Name Type Description
vector1 Vector
vector2 Vector
Since:
  • 0.2.0-alpha
Source:
Returns:
  • The dot product
Type
Number

<static> getLength(vector)

Get length of the vector

Parameters:
Name Type Description
vector Vector
Source:
Returns:
  • The length of the vector
Type
Number

<static> rotate(x, y, a)

Rotate a vector (x,y) by angle a

Parameters:
Name Type Description
x Number

x-coordinate

y Number

y-coordinate

a Number

Angle in radians

Source:
Returns:
Type
Vector

<static> scale(vector, scalar)

Multiply a vector by a scalar

Parameters:
Name Type Description
vector Vector
scalar Number
Source:
Returns:
Type
Vector

<static> subtract(vector1, vector2)

Perform vector subtraction

Parameters:
Name Type Description
vector1 Vector
vector2 Vector
  • @param {Boolean} [newObj = true] - Boolean that determines the return value. If true, then it returns a new Vector object vector such that vector.x === vector1.x - vector2.x and vector.x === vector1.y - vector2.y

If false, then vector2.x is subtracted from vector1.x, vector2.y is subtracted from vector1.y and then vector1 is returned.

Source:
Returns:
  • The difference between the two vectors. New object if newObj is true. Returns vector1 otherwise.
Type
Vector

<static> svgVector(x, y)

Get SVG point

Parameters:
Name Type Description
x Number
y Number
Source:
Returns:
  • SVG Vector String
Type
String

<static> unitVector(vector)

Get normalized vector of some vector.

Parameters:
Name Type Description
vector Vector

Vector to normalize.

Source:
Returns:
  • The Unit Vector
Type
Vector

<static> vectorToArray(vertex, ray1, ray2)

Gets angle between two lines that both end at vertex.

That is, suppose that A is the point ray1, B is the point ray2 and that C is the point vertex. Then, vectorToArray returns the angle between the lines AC and BC.

Parameters:
Name Type Description
vertex Vector
ray1 Vector
ray2 Vector
Since:
  • 0.2.0-alpha
Source:
Returns:
  • The angle
Type
Number