An abstract Vector object.
It’s defined by x, y components or rho (length) and phi (angle relative to X axis in radians).
Parameters : | *args : {two scalars, vector, point, (list, tuple of length 2)}
**kwargs : coordinates={“cartesian”, “polar”}, optional |
---|---|
Raises : | TypeError :
|
Attributes
normalized | [Vector] Get a normalized self. |
phi | [scalar] Get the angle (radians). |
rho | [scalar] Get the length of the Vector (polar coordinates). |
x | [scalar] Get the x component of the Vector. |
y | [scalar] Get the y component of the Vector. |
Methods
__add__(vector) | Add two vectors. |
__contains__(x) | Searches for x in “itself”. |
__getitem__(idx) | Return values as a list for easier acces some times. |
__len__() | The length of a Vector is 2. |
__mul__(arg) | Calculates the dot product with another Vector, or |
__neg__() | Turns self to 180 degrees and returns the new Vector. |
__sub__(vector) | Subtraction of two vectors. |
_calculate_cartesian_coords() | Helper function for internally calculating self.x and self.y. |
_calculate_polar_coords() | Helper function for internally calculating self.rho and self.phi. |
cross(arg) | Calculates the cross product with another Vector, as defined |
dot(arg) | Calculates the dot product with another Vector, or |
intersection(obj) | Return points of intersection if any. |
parallel_to(obj) | Is self parallel with obj? |
perpendicular_to(obj) | Is self perpendicular to obj? |
random_direction() | Create a randomly oriented Vector (with phi in the |
rotate(theta[, angle]) | Rotate self by theta degrees. |
translate(*args) | Dummy function since it doesn’t make sense to translate a |
Detailed description
An abstract Vector object.
It’s defined by x, y components or rho (length) and phi (angle relative to X axis in radians).
Parameters : | *args : {two scalars, vector, point, (list, tuple of length 2)}
**kwargs : coordinates={“cartesian”, “polar”}, optional |
---|---|
Raises : | TypeError :
|
Add two vectors.
Parameters : | vector : vector
|
---|---|
Returns : | A new vector with components ``self.x + vector.x``, :
|
Searches for x in “itself”. If we’re talking about a Point or a Vector then this searches within their components (x, y). For everything else it searches within the list of points (vertices).
Parameters : | x : {point, scalar}
|
---|---|
Returns : | out : {True, False}
|
Calculates the dot product with another Vector, or multiplication by scalar.
For more details see dot.
Turns self to 180 degrees and returns the new Vector.
Returns : | out : vector
|
---|
Subtraction of two vectors.
It is __add__ passed with turnerd round vector.
Helper function for internally calculating self.x and self.y.
Raises : | ValueError :
|
---|
Helper function for internally calculating self.rho and self.phi.
Calculates the cross product with another Vector, as defined in 2D space (not really a cross product since it gives a scalar, not another Vector).
Parameters : | arg : vector
|
---|---|
Returns : | res : float
|
Raises : | TypeError :
|
Calculates the dot product with another Vector, or multiplication by scalar.
Parameters : | arg : {scalar, vector} |
---|---|
Returns : | res : {float, vector}
|
Raises : | TypeError :
|
Return points of intersection if any.
This method just calls the intersection method on the other objects that have it implemented.
Parameters : | obj : geometric object
|
---|---|
Returns : | ret : {point, None}
|
Is self parallel with obj?
Find out if this Vector is parallel with another object (Vector or Line-like). Since we are in a 2D plane, we can use the geometric interpretation of the cross product.
Parameters : | obj : {vector, line-like}
|
---|---|
Returns : | res : {True, False}
|
Is self perpendicular to obj?
Find out if this Vector is perpendicular to another object (Vector or Line-like). If the dot product between the two vectors is 0 then they are perpendicular.
Parameters : | obj : {vector, line-like}
|
---|---|
Returns : | res : {True, False}
|
[scalar] Get the angle (radians).
Get the angle (in radians) of the Vector with the X axis (polar coordinates). phi will always be mapped to [0, 2PI).
[Arnon1983] | Arnon et al., A Linear Time Algorithm for the Minimum Area Rectangle Enclosing a Convex Polygon” (1983), Computer Science Technical Reports. Paper 382 |
[WPolygon] | http://en.wikipedia.org/wiki/Polygon |