Vector2D
Canonical path: NemAll_Python_Geometry.Vector2D
Representation class for 2D Vector.
CrossProduct
DotProduct
DotProduct(vec: Vector2D) -> float
Dot product operator.
Where \(\vec{a}\) is this vector.
Parameters:
-
vec
(Vector2D
) –Vector b
Returns:
-
float
–double.
Examples:
Calculate dot product of a unit vector along X axis and a vector perpendiular to it
Calculate dot product of the same vector and a vector parallel to it
GetAngle
GetAngle() -> Angle
GetAngleSigned
GetAngleSigned() -> Angle
GetCoords
GetCoords() -> tuple[float, float]
GetLength
IsZero
Check the coords [0.0, 0.0] (binary comparison)
Returns:
-
bool
–Is zero? true/false
Normalize
overloaded
Normalize the vector to a unit vector, according to the formula:
Where \(\vec{a}\) is this vector.
This is a mutator method - it changes the vector, on which it is called
Examples:
Normalize the vector to a defined length, according to the formula:
Where \(\vec{a}\) is this vector and \(l\) is the desired length.
This is a mutator method - it changes the vector, on which it is called.
Parameters:
-
length
(float
) –new length of vector.
Examples:
Orthogonal
Orthogonal(counterClockwise: bool = True) -> Vector2D
Get orthogonal vector
Parameters:
-
counterClockwise
(bool
, default:True
) –Orientation of orthogonal vector
Returns:
-
Vector2D
–Orthogonal vector
Examples:
Reverse
Reverse() -> Vector2D
Compute reversed vector
Method calculate vector with reversed orientation.
Returns:
-
Vector2D
–Reversed vector
Set
overloaded
Set(vec: Vector2D)
Initialize from x,y coordinates.
Parameters:
-
x
(float
) –coordinate.
-
y
(float
) –coordinate.
Values
Get copy of X,Y coordinates as python list
Returns:
-
list[float]
–Vector coordinates in a list
__add__
__eq__
__eq__(vec: Vector2D) -> bool
Comparison of vectors without tolerance.
Be careful, this method work without tolerance!
Parameters:
-
vec
(Vector2D
) –Compared vector.
Returns:
-
bool
–True when points are equal, otherwise false.
__iadd__
__imul__
overloaded
In-place matrix transformation.
Where \(\vec{a}\) is this vector and \(M\) is the transformation matrix.
Parameters:
-
matrix
(Matrix2D
) –Transformation matrix.
Returns:
-
Vector2D
–Vector2D.
Examples:
rotation_3
is a transformation matrix that rotates by 90° around the origin. Apply it to the vector like:
__imul__(factor: float) -> Vector2D
In-place multiplication operator.
Where \(\vec{a}\) is this vector and \(s\) is the scaling multiplier.
Parameters:
-
factor
(float
) –Scale factor
Returns:
-
Vector2D
–New vector
Examples:
__init__
overloaded
Initialize zero vector.
__init__(vec: Vector2D)
__init__(angle: Angle, length: float)
Initialize from angle and length, according to the formula:
Where \(\vec{a}\) is this vector, \(l\) is the length and \(\alpha\) is the angle.
Parameters:
-
angle
(Angle
) –base angle.
-
length
(float
) –length of vector (must be greater then zero).
Initialize from X and Y coordinates.
Parameters:
-
x
(float
) –X coordinate of vector.
-
y
(float
) –Y coordinate of vector.
__init__(endPoint: Point2D)
Initialize from only the end point.
Parameters:
-
endPoint
(Point2D
) –End point of the vector (startpoint is 0./0.)
__init__(vec: Vector3D)
Initialize from a 3D vector.
Parameters:
-
vec
(Vector3D
) –2D vector which will be copied to the 3D vector.
__isub__
__itruediv__
__itruediv__(divider: float) -> Vector2D
In-place division operator.
Where \(\vec{a}\) is this vector and \(s\) is the scaling divider.
Parameters:
-
divider
(float
) –scaling divider
Returns:
-
Vector2D
–New vector
Examples:
__mul__
overloaded
Matrix transformation.
Where \(\vec{a}\) is this vector and \(M\) is the transformation matrix.
Parameters:
-
matrix
(Matrix2D
) –Transformation matrix.
Returns:
-
Vector2D
–Vector2D.
Examples:
rotation_3
is a transformation matrix that rotates by 90° around the origin. Apply it to the vector like:
__mul__(factor: float) -> Vector2D
Multiplication operator.
Where \(\vec{a}\) is this vector and \(s\) is the scaling multiplier.
Parameters:
-
factor
(float
) –Scale factor
Returns:
-
Vector2D
–New vector
Examples:
__ne__
__ne__(vec: Vector2D) -> bool
Comparison of vectors without tolerance.
Be careful, this method work without tolerance!
Parameters:
-
vec
(Vector2D
) –Compared vector.
Returns:
-
bool
–True when points are not equal, otherwise false.