Vector2D
Canonical path: NemAll_Python_Geometry.Vector2D
Representation class for 2D Vector.
Methods:
-
CrossProduct–Cross(vector) product operator.
-
DotProduct–Dot(sxcalar) product.
-
GetAngle–Get vector angle.
-
GetAngleSigned–Get vector angle.
-
GetCoords–Get copy of X, Y coordinates.
-
GetLength–Get vector length.
-
IsZero–Check the coords [0.0, 0.0] (binary comparison)
-
Normalize–Overloaded function. See individual overloads.
-
Orthogonal–Compute 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__–Addition assignment operator.
-
__idiv__–Multiply the vector by a factor (scalar multiplication)
-
__imul__–Overloaded function. See individual overloads.
-
__init__–Overloaded function. See individual overloads.
-
__isub__–Subtraction assignment operator.
-
__mul__–Overloaded function. See individual overloads.
-
__ne__–Comparison of vectors without tolerance.
-
__repr__–Convert to string
-
__sub__–Subtraction operator.
-
__truediv__–Multiply the vector by a factor (scalar multiplication)
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(sxcalar) product.
Formula: S = Va . Vb = Va1 * Va2 + Vb1 * Vb2 Va is this Vector
Parameters:
-
vec(Vector2D) –Vector(Vb).
Returns:
-
float–double.
GetAngle
GetAngle() -> Angle
GetAngleSigned
GetAngleSigned() -> Angle
GetCoords
GetCoords() -> tuple[float, float]
Get copy of X, Y coordinates.
Returns:
-
tuple[float, float]–tuple(X coordinate of vector, Y coordinate of vector)
GetLength
Get vector length.
Formula: Result(double) = ||Va|| Va is this vector
Returns:
-
float–double.
IsZero
Check the coords [0.0, 0.0] (binary comparison)
Returns:
-
bool–Is zero? true/false
Normalize
overloaded
Normalize vector.
Formula: Vn(a1/||Va||, a2/||Va||) Va is this vector This method is checked and throwing a geometry exception when vector is zero.
Normalize vector to new length.
Formula: Vn(a1 * length / ||Va||, a2 * length / ||Va||) Va is this vector This method is checked and throwing a geometry exception when vector is zero.
Parameters:
-
length(float) –new length of vector.
Orthogonal
Orthogonal(counterClockwise: bool = True) -> Vector2D
Compute orthogonal vector
Method calculate orthogonal vector. Sample:
vec = Vector2D(100., 0) vec.Orthogonal()
vec = (0., 100.);
Parameters:
-
counterClockwise(bool, default:True) –Orientation of orthogonal vector
Returns:
-
Vector2D–Orthogonal vector
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]–X coordinate of vector.,
-
list[float]–Y coordinate of vector.
__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__
__idiv__
__idiv__(divider: float) -> Vector2D
Multiply the vector by a factor (scalar multiplication)
Parameters:
-
divider(float) –scaling divider
Returns:
-
Vector2D–New vector
__imul__
overloaded
__imul__(factor: float) -> Vector2D
Multiply the vector by a factor (scalar multiplication)
Parameters:
-
factor(float) –Scale factor
Returns:
-
Vector2D–New vector
__init__
overloaded
Initialize
__init__(vec: Vector2D)
__init__(angle: Angle, length: float)
Constructor.
Create vector from the angle and from the length. Formula: [X_COORD, Y_COORD] = [lengthcos(angle), lengthsin(angle)]
Parameters:
-
angle(Angle) –base angle.
-
length(float) –length of vector (must be greater then zero).
Constructor.
Initialize vector from single coordinates.
Parameters:
-
x(float) –X coordinate of vector.
-
y(float) –Y coordinate of vector.
__init__(endPoint: Point2D)
Create a vector from a 2D point
Parameters:
-
endPoint(Point2D) –End point of the vector (startpoint is 0./0.)
__init__(vec: Vector3D)
Copy constructor.
Copy only X_COORD and Y_COORD from vector.
Parameters:
-
vec(Vector3D) –2D vector which will be copied to the 3D vector.
__isub__
__mul__
overloaded
__mul__(factor: float) -> Vector2D
Multiply the vector by a factor (scalar multiplication)
Parameters:
-
factor(float) –Scale factor
Returns:
-
Vector2D–New vector
__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.