Table of contents
Vector2() | Vectors in 2 dimensional euclidean space.
|
Class: Vector2()
Vectors in 2 dimensional euclidean space.
Normalize
Normalize a copy of vector.
Parameters
Examples
assert((x * 3 + y * 4).Normalize() == x * 0.6 + y * 0.8)
R180
Rotate a copy of a vector by 180 degrees.
Parameters
Examples
assert(x.R180() == -x)
R270
Rotate a vector by 270 degrees anticlockwise.
Parameters
Examples
assert(x.R270() == -y)
R90
Rotate a copy of a vector by 90 degrees anticlockwise.
Parameters
Examples
assert(x.R90() == y)
Swap
Swap the components of a copy of a vector.
Parameters
Examples
z = x + y * 2
Z = z.Swap()
assert(z != Z)
__abs__
Length of a vector.
Parameters
Examples
assert(abs(x * 3 + y * 4) == 5)
__add__ **+ **
Add the second vector to a copy of the first vector.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert(x + y == Vector2(1, 1))
__eq__ **==**
Whether two vectors are equal within a radius of floating point epsilon.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert(x * 2 + y - x - y == x)
__iadd__ **+=**
Add the second vector to the first vector.
Parameters
Name | Description
|
---|
this | other
|
Examples
X = x
X = X + x
assert(x == Vector2(1, 0) and X == Vector2(2, 0))
__imul__ ***=**
Multiply a vector by a scalar.
Parameters
Name | Description
|
---|
this | scalar
|
Examples
X = x
X = X * 2
assert(x == Vector2(1, 0) and X == Vector2(2, 0))
__init__
Create a vector.
Parameters
Name | Description
|
---|
this | x = 0
|
Examples
assert(x + y == Vector2(1, 1))
__isub__ **-=**
Subtract the second vector from the first vector.
Parameters
Name | Description
|
---|
this | other
|
Examples
X = x
X = X - x
assert(x == Vector2(1, 0) and X == Vector2(0, 0))
__itruediv__ **/=**
Divide a vector by a scalar.
Parameters
Name | Description
|
---|
this | scalar
|
Examples
X = x * 4
X = X / 2
assert(x == Vector2(1, 0) and X == Vector2(2, 0))
__mul__ *** **
Multiply a copy of vector by a scalar.
Parameters
Name | Description
|
---|
this | scalar
|
Examples
assert(x * 2 + y * 3 == Vector2(2, 3))
__neg__ **- **
Rotate a copy of a vector by 180 degrees.
Parameters
Examples
assert(- y == Vector2(0, -1))
__repr__
String representation of a vector.
Parameters
Examples
assert(repr(x + y * 2) == 'Vector2(1, 2)')
__sub__ **- **
Subtract the second vector from a copy of the first vector.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert(x - y == Vector2(1, -1))
__truediv__ **/ **
Divide a copy of a vector by a scalar.
Parameters
Name | Description
|
---|
this | scalar
|
Examples
assert((x * 4 + y * 2) / 2 == x * 2 + y)
angle
Angle in radians anticlockwise that the first vector must be rotated to point along the second vector normalized to the range: -pi to +pi.
Parameters
Examples
for i in range(-179, +179): # Anticlockwise angle from x
assert(Vector2.close
(x.angle(x * math.cos(dr(i)) + y * math.sin(dr(i))), dr(i)))
area
Signed area of the parallelogram defined by the two vectors. The area is negative if the second vector appears to the right of the first if they are both placed at the origin and the observer stands against the z-axis in a left handed coordinate system.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert((x + y).area(-x + y) == 2)
clone
Clone a vector to allow it to be modified by other operations.
Parameters
Examples
z = x + y * 2
Z = z.clone()
assert(z == Z)
close
Whether two numbers are close.
Parameters
Examples
assert(Vector2.close(0, Vector2.closeRadius() / 2))
closeRadius
Two numbers are equal if they are less than this far apart.
Parameters
Examples
assert(Vector2.closeRadius() < 1)
cos
cos(angle between two vectors).
Parameters
Name | Description
|
---|
this | other
|
Examples
assert(Vector2.close((x + y).cos(y), 1 / r2))
assert(Vector2.close( x.cos(x + yr3), 0.5))
distance
Distance between the points identified by two vectors when placed on the same point.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert((x * 3 + y * 4).distance (-(x * 3 + y * 4)) == 10)
distance2
Distance squared between the points identified
by two vectors when placed on the same point.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert((x * 3 + y * 4).distance2(-(x * 3 + y * 4)) == 100)
dot
Dot product of two vectors.
Parameters
Name | Description
|
---|
this | other
|
Examples
assert((x * 2 + y).dot(x + y * 3) == 5)
length
Length of a vector.
Parameters
Examples
assert((x * 3 + y * 4).length() == 5)
length2
Length squared of a vector.
Parameters
Examples
assert((x * 3 + y * 4).length2() == 25)
nonZero
Whether a number is non zero.
Parameters
Examples
assert(Vector2.nonZero(Vector2.closeRadius()))
normalize
Normalize a vector.
Parameters
Examples
assert((x * 3 + y * 4).clone().normalize() == x * 0.6 + y * 0.8)
r180
Rotate a vector by 180 degrees.
Parameters
Examples
assert(x.clone().r180() == -x)
r270
Rotate a copy of a vector by 270 degrees anticlockwise.
Parameters
Examples
assert(x.clone().r270() == -y)
r90
Rotate a vector by 90 degrees anticlockwise.
Parameters
Examples
assert(x.clone().r90() == y)
sin
sin(angle between two vectors).
Parameters
Name | Description
|
---|
this | other
|
Examples
assert(Vector2.close((x + y).sin(y), 1 / r2))
assert(Vector2.close( x.sin(x + yr3), r3 / 2))
smallestAngleToNormalPlane
The smallest angle between the second vector and a plane normal to the first vector.
Parameters
Examples
assert(Vector2.close(dr( 0), y.smallestAngleToNormalPlane( x))) # First vector is y, second vector is 0 degrees anti-clockwise from x axis
assert(Vector2.close(dr(+45), y.smallestAngleToNormalPlane( x + y))) # +45
assert(Vector2.close(dr(+90), y.smallestAngleToNormalPlane( y))) # +90
assert(Vector2.close(dr(+45), y.smallestAngleToNormalPlane(-x + -y))) # +135
assert(Vector2.close(dr( 0), y.smallestAngleToNormalPlane(-x))) # +180
assert(Vector2.close(dr(+45), y.smallestAngleToNormalPlane(-x + -y))) # +225
assert(Vector2.close(dr(+90), y.smallestAngleToNormalPlane( -y))) # +270
assert(Vector2.close(dr(+45), y.smallestAngleToNormalPlane(-x + -y))) # +315
assert(Vector2.close(dr( 0), y.smallestAngleToNormalPlane( x))) # +360
swap
Swap the components of a vector.
Parameters
Examples
assert((x + y * 2).swap() == y + x * 2)
zeroAndUnits
Create the useful vectors: zero=(0,0), x=(1,0), y=(0,1).
Parameters
Examples
assert(zero != x and zero != y and x != y)
Possible improvements to documentation
/home/phil/python/Vector2/Vector2.py
No parameter definitions for Vector2().__init__
|
No parameter definitions for Vector2().__repr__
|
No parameter definitions for Vector2().__neg__
|
No parameter definitions for Vector2().__abs__
|
No parameter definitions for Vector2().__eq__
|
No parameter definitions for Vector2().__iadd__
|
No parameter definitions for Vector2().__add__
|
No parameter definitions for Vector2().__isub__
|
No parameter definitions for Vector2().__sub__
|
No parameter definitions for Vector2().__imul__
|
No parameter definitions for Vector2().__mul__
|
No parameter definitions for Vector2().__itruediv__
|
No parameter definitions for Vector2().__truediv__
|
No parameter definitions for Vector2().zeroAndUnits
|
No parameter definitions for Vector2().clone
|
No parameter definitions for Vector2().closeRadius
|
No parameter definitions for Vector2().close
|
No parameter definitions for Vector2().nonZero
|
No parameter definitions for Vector2().length
|
No parameter definitions for Vector2().length2
|
No parameter definitions for Vector2().distance
|
No parameter definitions for Vector2().distance2
|
No parameter definitions for Vector2().normalize
|
No parameter definitions for Vector2().Normalize
|
No parameter definitions for Vector2().dot
|
No parameter definitions for Vector2().area
|
No parameter definitions for Vector2().cos
|
No parameter definitions for Vector2().sin
|
No parameter definitions for Vector2().angle
|
No parameter definitions for Vector2().smallestAngleToNormalPlane
|
No parameter definitions for Vector2().r90
|
No parameter definitions for Vector2().R90
|
No parameter definitions for Vector2().r180
|
No parameter definitions for Vector2().R180
|
No parameter definitions for Vector2().r270
|
No parameter definitions for Vector2().R270
|
No parameter definitions for Vector2().swap
|
No parameter definitions for Vector2().Swap
|