Vector2D
Canonical path: NemAll_Python_Geometry.Vector2D
Representation class for 2D Vector.
Methods:
-
CrossProduct–Cross(vector) product operator, according to the formula:
-
DotProduct–Dot product operator.
-
GetAngle–Get the angle to X axis
-
GetAngleSigned–Get the signed angle to X axis
-
GetCoords–Get copy of X, Y coordinates.
-
GetLength–Get the length of the vector, according to the formula:
-
IsZero–Check the coords [0.0, 0.0] (binary comparison)
-
Normalize–Overloaded function. See individual overloads.
-
Orthogonal–Get orthogonal vector
-
Reverse–Compute reversed vector
-
Set–Overloaded function. See individual overloads.
-
Values–Get copy of X,Y coordinates as python list
-
__add__–Addition operator.
-
__eq__–Comparison of vectors without tolerance.
-
__iadd__–In-place addition operator.
-
__imul__–Overloaded function. See individual overloads.
-
__init__–Overloaded function. See individual overloads.
-
__isub__–In-place subtraction operator.
-
__itruediv__–In-place division operator.
-
__mul__–Overloaded function. See individual overloads.
-
__ne__–Comparison of vectors without tolerance.
-
__repr__–Convert to string
-
__sub__–Subtraction operator.
-
__truediv__–Division operator.
Attributes:
-
To3D(Vector3D) –convert to 3D3
-
X(float) –Get the X coordinate reference.
-
Y(float) –Get the Y coordinate reference.
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.