Skip to content

Vector2D

Class full path: NemAll_Python_Geometry.Vector2D

Representation class for 2D Vector.

Attributes

X: float property writable

Get the X coordinate reference.

Y: float property writable

Get the Y coordinate reference.

Functions

CrossProduct(vec)

Cross(vector) product operator.

Formula: Va = Va x Vb Va is this Vector

Parameters:

Name Type Description Default
vec Vector2D

Vector(Vb).

required

Returns:

Type Description
Vector3D

new Vector(Vc).

DotProduct(vec)

Dot(sxcalar) product.

Formula: S = Va . Vb = Va1 * Va2 + Vb1 * Vb2 Va is this Vector

Parameters:

Name Type Description Default
vec Vector2D

Vector(Vb).

required

Returns:

Type Description
float

double.

GetAngle()

Get vector angle.

Returns:

Type Description
Angle

Angle in a range <0, 2*PI> (normalized 2pi).

GetAngleSigned()

Get vector angle.

equivalent to zfno()

Returns:

Type Description
Angle

Angle in a range <-PI..0..PI>

GetCoords()

Get copy of X,Y coordinates.

Returns:

Type Description
float

tuple(X coordinate of vector,

float

Y coordinate of vector)

GetLength()

Get vector length.

Formula: Result(double) = ||Va|| Va is this vector

Returns:

Type Description
float

double.

IsZero()

Check the coords [0.0, 0.0] (binary comparison)

Returns:

Type Description
bool

Is zero? true/false

Normalize overload

Normalize()

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(length)

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:

Name Type Description Default
length float

new length of vector.

required

Orthogonal(counterClockwise=True)

Compute orthogonal vector

Method calculate orthogonal vector. Sample: vec = Vector2D(100., 0) vec.Orthogonal()

vec = (0., 100.);

Parameters:

Name Type Description Default
counterClockwise bool

Orientation of orthogonal vector

True

Returns:

Type Description
Vector2D

Orthogonal vector

Reverse()

Compute reversed vector

Method calculate vector with reversed orientation.

Returns:

Type Description
Vector2D

Reversed vector

Set overload

Set(vec)

Initialize from vector 2D.

Parameters:

Name Type Description Default
vec Vector2D

Vector.

required
Set(x, y)

Initialize from x,y coordinates.

Parameters:

Name Type Description Default
x float

coordinate.

required
y float

coordinate.

required
Set(startPoint, endPoint)

Initialize vector from two points.

Parameters:

Name Type Description Default
startPoint Point2D

start point of vector.

required
endPoint Point2D

end point of vector.

required

Values()

Get copy of X,Y coordinates as python list

Returns:

Type Description
list[float]

X coordinate of vector.,

list[float]

Y coordinate of vector.

__add__(vec)

Addition operator.

Formula: Vc = Va + Vb Va is this Vector.

Parameters:

Name Type Description Default
vec Vector2D

Vector(Vb).

required

Returns:

Type Description
Vector2D

new Vector(Vc).

__eq__(vec)

Comparison of vectors without tolerance.

Be careful, this method work without tolerance!

Parameters:

Name Type Description Default
vec Vector2D

Compared vector.

required

Returns:

Type Description
bool

True when points are equal, otherwise false.

__iadd__(vec)

Addition assignment operator.

Formula: Va = Va + Vb Va is this Vector.

Parameters:

Name Type Description Default
vec Vector2D

Vb Vector.

required

Returns:

Type Description
Vector2D

Reference to vector.

__idiv__(divider)

Multiply the vector by a factor (scalar multiplication)

Parameters:

Name Type Description Default
divider float

scaling divider

required

Returns:

Type Description
Vector2D

New vector

__imul__ overload

__imul__(matrix)

Matrix transformation.

Formula: Vector(this) = Vector(this) * matrix

Parameters:

Name Type Description Default
matrix Matrix2D

Transformation matrix.

required

Returns:

Type Description
Vector2D

Vector2D.

__imul__(factor)

Multiply the vector by a factor (scalar multiplication)

Parameters:

Name Type Description Default
factor float

Scale factor

required

Returns:

Type Description
Vector2D

New vector

__init__ overload

__init__()

Initialize

__init__(vec)

Copy constructor.

Parameters:

Name Type Description Default
vec Vector2D

Vector which will be copied.

required
__init__(angle, length)

Constructor.

Create vector from the angle and from the length. Formula: [X_COORD, Y_COORD] = [lengthcos(angle), lengthsin(angle)]

Parameters:

Name Type Description Default
angle Angle

base angle.

required
length float

length of vector (must be greater then zero).

required
__init__(x, y)

Constructor.

Initialize vector from single coordinates.

Parameters:

Name Type Description Default
x float

X coordinate of vector.

required
y float

Y coordinate of vector.

required
__init__(startPoint, endPoint)

Constructor.

Initialize vector from two points.

Parameters:

Name Type Description Default
startPoint Point2D

start point of vector.

required
endPoint Point2D

end point of vector.

required
__init__(endPoint)

Create a vector from a 2D point

Parameters:

Name Type Description Default
endPoint Point2D

End point of the vector (startpoint is 0./0.)

required
__init__(vec)

Copy constructor.

Copy only X_COORD and Y_COORD from vector.

Parameters:

Name Type Description Default
vec Vector3D

2D vector which will be copied to the 3D vector.

required

__isub__(vec)

Subtraction assignment operator.

Formula: Va = Va - Vb Va is this Vector.

Parameters:

Name Type Description Default
vec Vector2D

Vb Vector.

required

Returns:

Type Description
Vector2D

Reference to vector.

__mul__ overload

__mul__(vec)

Cross(vector) product operator.

Formula: Vc = Va x Vb Va is this Vector

Parameters:

Name Type Description Default
vec Vector2D

Vector(Vb).

required

Returns:

Type Description
Vector3D

new Vector(Vc).

__mul__(matrix)

Matrix transformation.

Formula: Result = Vector(this) * matrix

Parameters:

Name Type Description Default
matrix Matrix2D

Transformation matrix.

required

Returns:

Type Description
Vector2D

Vector2D.

__mul__(factor)

Multiply the vector by a factor (scalar multiplication)

Parameters:

Name Type Description Default
factor float

Scale factor

required

Returns:

Type Description
Vector2D

New vector

__ne__(vec)

Comparison of vectors without tolerance.

Be careful, this method work without tolerance!

Parameters:

Name Type Description Default
vec Vector2D

Compared vector.

required

Returns:

Type Description
bool

True when points are not equal, otherwise false.

__repr__()

Convert to string

__sub__(vec)

Subtraction operator.

Formula: Vc = Va - Vb Va is this Vector

Parameters:

Name Type Description Default
vec Vector2D

Vector(Vb).

required

Returns:

Type Description
Vector2D

new Vector(Vc).

__truediv__(divider)

Multiply the vector by a factor (scalar multiplication)

Parameters:

Name Type Description Default
divider float

scaling divider

required

Returns:

Type Description
Vector2D

New vector