Class Index | File Index

Classes


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.

{pv.Vector} 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:
{pv.Vector} a new vector.

{pv.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:
{pv.Vector} a unit vector.

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

{pv.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
the x coordinate to add.
{number} y
the y coordinate to add.
Returns:
{pv.Vector} a new vector.

{pv.Vector} times(k)
Returns a scaled copy of this vector: ⟨x * k, y * k⟩. To perform the equivalent divide operation, use 1 / k.
Parameters:
{number} k
the scale factor.
Returns:
{pv.Vector} a scaled vector.

Documentation generated by JsDoc Toolkit 2.3.2 on Sun May 30 2010 18:10:25 GMT-0700 (PDT)