# Class pv.Vector

Represents a two-dimensional vector; a 2-tuple ⟨x, y⟩. The intent of this class is to simplify vector math. Note that in performance-sensitive cases it may be more efficient to represent 2D vectors as simple objects with x and y attributes, rather than using instances of this class.
Defined in: Vector.js.

Class Summary
Constructor Attributes Constructor Name and Description

pv.Vector(x, y)
Constructs a pv.Vector for the specified x and y coordinate.
Method Summary
Method Attributes Method Name and Description

dot(x, y)
Returns the dot product of this vector and the vector v: x * v.x + y * v.y.

Returns the magnitude of this vector, defined as sqrt(x * x + y * y).

minus(x, y)
Returns this vector minus the vector v: ⟨x - v.x, y - v.y⟩.

norm()
Returns a normalized copy of this vector: a vector with the same direction, but unit length.

perp()
Returns a vector perpendicular to this vector: ⟨-y, x⟩.

plus(x, y)
Returns this vector plus the vector v: ⟨x + v.x, y + v.y⟩.

times(k)
Returns a scaled copy of this vector: ⟨x * k, y * k⟩.
Class Detail
pv.Vector(x, y)
Constructs a pv.Vector for the specified x and y coordinate. This constructor should not be invoked directly; use pv.vector instead.
Parameters:
{number} x
the x coordinate.
{number} y
the y coordinate.
Method Detail
{number} dot(x, y)
Returns the dot product of this vector and the vector v: x * v.x + y * v.y. If only one argument is specified, it is interpreted as the vector v.
Parameters:
{number} x
the x coordinate to dot.
{number} y
the y coordinate to dot.
Returns:
{number} a dot product.

{number} length()
Returns the magnitude of this vector, defined as sqrt(x * x + y * y).
Returns:
{number} a length.

minus(x, y)
Returns this vector minus the vector v: ⟨x - v.x, y - v.y⟩. If only one argument is specified, it is interpreted as the vector v.
Parameters:
{number} x
the x coordinate to subtract.
{number} y
the y coordinate to subtract.
Returns:
a new vector.

norm()
Returns a normalized copy of this vector: a vector with the same direction, but unit length. If this vector has zero length this method returns a copy of this vector.
Returns:
a unit vector.

perp()
Returns a vector perpendicular to this vector: ⟨-y, x⟩.
Returns:
a perpendicular vector.

plus(x, y)
Returns this vector plus the vector v: ⟨x + v.x, y + v.y⟩. If only one argument is specified, it is interpreted as the vector v.
Parameters:
{number} x
{number} y