Class pv.Vector
Represents a two-dimensional vector; a 2-tuple ⟨x, y⟩.
Defined in: Vector.js.
Constructor Attributes | Constructor Name and Description |
---|---|
pv.Vector(x, y)
Constructs a pv.Vector for the specified x and y
coordinate.
|
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.
|
|
length()
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⟩.
|
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.
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.
Returns the magnitude of this vector, defined as sqrt(x * x + y * y).
- Returns:
- {number} a length.
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.
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.
Returns a vector perpendicular to this vector: ⟨-y, x⟩.
- Returns:
- {pv.Vector} a perpendicular vector.
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.
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.