Skip to content

Vector3D

Canonical path: NemAll_Python_Geometry.Vector3D

Representation class for 3D Vector.

To2D property

To2D: Vector2D

convert to 2D3

X property writable

X: float

Get the X coordinate reference.

Y property writable

Y: float

Get the Y coordinate reference.

Z property writable

Z: float

Get the Z coordinate reference.

CrossProduct

CrossProduct(vec: Vector3D)

Cross(vector) product operator, according to the formula:

\[ \vec{a} = \vec{a} \times \vec{b} = \begin{pmatrix} a_y b_z - a_z b_y \\ a_z b_x - a_x b_z \\ a_x b_y - a_y b_x \end{pmatrix} \]

Where \(\vec{a}\) is this vector.

This is a mutator method - it changes the vector, on which it is called. For an accessor method, see Normal()

Parameters:

Examples:

Calculate a cross product vector of a unit vector along X axis and another one along Y axis, like:

>>> vec = Vector3D(1, 0, 0)
>>> vec.CrossProduct(Vector3D(0, 1, 0))
>>> vec
Vector3D(0, 0, 1)

DotProduct

DotProduct(vec: Vector3D) -> float

Dot product operator.

\[ s = \vec{a} \cdot \vec{b} = \|\vec{a}\| \|\vec{b}\| \cos(\theta) \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

  • float

    double.

Examples:

Calculate dot product of a unit vector along X axis and a vector perpendiular to it

>>> vec = Vector3D(1, 0, 0)
>>> vec.DotProduct(Vector3D(0, 1, 0))
0.0

Calculate dot product of the same vector and a vector parallel to it

>>> vec.DotProduct(Vector3D(2, 0, 0))
2.0

GetCoords

GetCoords() -> tuple[float, float, float]

Get copy of X,Y,Z coordinates

Returns:

  • float

    X coodinate

  • float

    Y coodinate

  • float

    Z coodinate

Examples:

>>> Vector3D(1.0, 2.0, 3.0).GetCoords()
(1.0, 2.0, 3.0)

GetLength

GetLength() -> float

Get the length of the vector, according to the formula:

\[ l = \|\vec{a}\| = \sqrt{a_x^2 + a_y^2 + a_z^2} \]

Where \(\vec{a}\) is this vector.

Returns:

  • float

    Length of the vector

Examples:

>>> Vector3D(1, 1, 1).GetLength()
1.7320508075688772

GetLengthSquare

GetLengthSquare() -> float

Get the square of the length of the vector, according to the formula:

\[ l = \|\vec{a}\|^2 = a_x^2 + a_y^2 + a_z^2 \]

Where \(\vec{a}\) is this vector.

Returns:

  • float

    double.

Examples:

>>> Vector3D(1, 1, 1).GetLengthSquare()
3.0

IsZero

IsZero() -> bool

Check the coords [0.0, 0.0, 0.0]

If the coords are zero, the return value is true. If the coords aren't zero, the return value is false.

Returns:

  • bool

    Is zero? true/false

Normal

Normal(vec: Vector3D) -> Vector3D

Cross(vector) product operator, according to the formula:

\[ \vec{a} = \vec{a} \times \vec{b} \]

Where \(\vec{a}\) is this vector.

This is an accessor method - it returns a new vector. For a mutator method, see CrossProduct()

Parameters:

Examples:

Calculate a cross product vector of a unit vector along X axis and another one along Y axis

>>> vec = Vector3D(1, 0, 0)
>>> vec.Normal(Vector3D(0, 1, 0))
Vector3D(0, 0, 1)

Normalize overloaded

Normalize() -> eGeometryErrorCode

Normalize the vector to a unit vector, according to the formula:

\[ \vec{a} = \frac{\vec{a}}{\|\vec{a}\|} \]

Where \(\vec{a}\) is this vector.

This is a mutator method - it changes the vector, on which it is called

Returns:

Examples:

>>> vec = Vector3D(1, 1, 1)
>>> vec.Normalize()
NemAll_Python_Geometry.eGeometryErrorCode.eOK
>>> vec
Vector3D(0.577..., 0.577..., 0.577...)

Normalising a zero vector results in a geometry error

>>> Vector3D().Normalize()
NemAll_Python_Geometry.eGeometryErrorCode.eError
Normalize(length: float) -> eGeometryErrorCode

Normalize the vector to a defined length, according to the formula:

\[ \vec{a} = \frac{\vec{a}}{\|\vec{a}\|} \cdot l \]

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.

Returns:

Examples:

>>> vec = Vector3D(1, 1, 1)
>>> vec.Normalize(2.0)
NemAll_Python_Geometry.eGeometryErrorCode.eOK
>>> vec
Vector3D(1.154..., 1.154..., 1.154...)
>>> vec.GetLength()
2.0

Project

Project(vec: Vector3D) -> Vector3D

Project the vector on another vector, according to the formula:

\[ \vec{c} = \frac{\vec{a} \cdot \vec{b}}{\|\vec{b}\|^2} \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

Examples:

Project a vector on X axis

>>> vec_x = Vector3D(1, 0, 0)
>>> vec_x.Project(Vector3D(2, 3, 4))
Vector3D(2, 0, 0)

Reverse

Reverse() -> Vector3D

Compute reversed vector

Method calculate vector with reversed orientation.

Returns:

Set overloaded

Set(vec: Vector3D)

Initialize from vector 3D.

Parameters:

Set(x: float, y: float, z: float)

Initialize from x,y,z coordinates.

Parameters:

  • x (float) –

    coordinate.

  • y (float) –

    coordinate.

  • z (float) –

    coordinate.

Set(startPoint: Point3D, endPoint: Point3D)

Initialize vector from two points.

Parameters:

  • startPoint (Point3D) –

    start point of vector.

  • endPoint (Point3D) –

    end point of vector.

Values

Values() -> list[float]

Get copy of X,Y,Z coordinates as python list

Returns:

  • list[float]

    list with vector coordinates X, Y and Z

__add__

__add__(vec: Vector3D) -> Vector3D

In-place addition operator, according to the formula:

\[ \vec{a} = \vec{a} + \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

Examples:

>>> vec = Vector3D(1, 2, 3)
>>> vec += Vector3D(4, 5, 6)
>>> vec
Vector3D(5, 7, 9)

__eq__

__eq__(vec: Vector3D) -> bool

Comparison of vectors without tolerance.

Be careful, this method work without tolerance!

Parameters:

Returns:

  • bool

    True when points are equal, otherwise false.

__iadd__

__iadd__(vec: Vector3D) -> Vector3D

In-place addition operator, according to the formula:

\[ \vec{a} = \vec{a} + \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

Examples:

>>> vec = Vector3D(1, 2, 3)
>>> vec += Vector3D(4, 5, 6)
>>> vec
Vector3D(5, 7, 9)

__imul__ overloaded

__imul__(vec: Vector3D) -> Vector3D

In-place cross(vector) product operator, according to the formula:

\[ \vec{a} = \vec{a} \times \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

  • Vector3D

    Reference to the cross(vector) product of vectors.

Examples:

>>> vec = Vector3D(1, 0, 0)
>>> vec *= Vector3D(0, 1, 0)
>>> vec
Vector3D(0, 0, 1)
__imul__(factor: float) -> Vector3D

In-place multiplication by a scalar factor, according to the formula:

\[ \vec{a} = \vec{a} \cdot s \]

Where \(\vec{a}\) is this vector and \(s\) is the scalar factor.

Parameters:

  • factor (float) –

    Scale factor

Returns:

Examples:

>>> vec = Vector3D(1, 2, 3)
>>> vec *= 2
>>> vec
Vector3D(2, 4, 6)
__imul__(matrix: Matrix2D) -> Vector3D

In-place 2D matrix transformation according to the formula:

\[ \vec{a} = \vec{a} \cdot M \]

Where \(\vec{a}\) is this vector.

Parameters:

  • matrix (Matrix2D) –

    2D transformation matrix.

Returns:

Examples:

rotation_3 is a transformation matrix that rotates by 90° around the origin. Apply it to a vector like:

>>> vec = Vector3D(1, 0, 0)
>>> vec *= rotation_3
>>> vec
Vector3D(0, 1, 0)
__imul__(matrix: Matrix3D) -> Vector3D

In-place 3D matrix transformation according to the formula:

\[ \vec{a} = \vec{a} \cdot M \]

Where \(\vec{a}\) is this vector.

Parameters:

  • matrix (Matrix3D) –

    3D transformation matrix.

Returns:

Examples:

When rotation_2 is a Matrix3D that rotates around X axis by 90°, apply it to a vector like:

>>> vec = Vector3D(0, 1, 0)
>>> vec *= rotation_2
>>> vec
Vector3D(0, 0, 1)

__init__ overloaded

__init__()

Initialize

__init__(vec: Vector2D)

Copy constructor.

Copy only X_COORD and Y_COORD from vector, Z_COORD is set to zero.

Parameters:

  • vec (Vector2D) –

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

__init__(vec: Vector3D)

Copy constructor.

Parameters:

  • vec (Vector3D) –

    vector which will be copied.

__init__(x: float, y: float, z: float)

Constructor.

Initialize vector from single coordinates.

Parameters:

  • x (float) –

    X coordinate of vector.

  • y (float) –

    Y coordinate of vector.

  • z (float) –

    Z coordinate of vector.

__init__(startPoint: Point3D, endPoint: Point3D)

Constructor.

Initialize vector from two points.

Parameters:

  • startPoint (Point3D) –

    start point of vector.

  • endPoint (Point3D) –

    end point of vector.

__init__(endPoint: Point3D)

Create a vector from a 3D point

Parameters:

  • endPoint (Point3D) –

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

__isub__

__isub__(vec: Vector3D) -> Vector3D

In-place subtraction operator, according to the formula:

\[ \vec{a} = \vec{a} - \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

Examples:

>>> vec = Vector3D(1, 2, 3)
>>> vec -= Vector3D(4, 5, 6)
>>> vec
Vector3D(-3, -3, -3)

__itruediv__

__itruediv__(divider: float) -> Vector3D

Divide the vector in-place by a scalar, according to the formula:

\[ \vec{a} = \frac{\vec{a}}{s} \]

Where \(\vec{a}\) is this vector and \(s\) is the scalar.

This is a mutator method - it changes the vector, on which it is called.

Parameters:

  • divider (float) –

    scaling divider

Returns:

Examples:

>>> vec = Vector3D(1, 1, 1)
>>> vec /= 2
>>> vec
Vector3D(0.5, 0.5, 0.5)

__mul__ overloaded

__mul__(vec: Vector3D) -> Vector3D

Cross(vector) product operator, according to the formula:

\[ \vec{c} = \vec{a} \times \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

Examples:

>>> Vector3D(1, 0, 0) * Vector3D(0, 1, 0)
Vector3D(0, 0, 1)
__mul__(factor: float) -> Vector3D

Multiply the vector by a scalar, according to the formula:

\[ \vec{c} = \vec{a} \cdot s \]

Where \(\vec{a}\) is this vector and \(s\) is the scalar factor.

Parameters:

  • factor (float) –

    Scale factor

Returns:

Examples:

>>> Vector3D(1, 0, 0) * 2
Vector3D(2, 0, 0)
__mul__(matrix: Matrix2D) -> Vector3D

Multiply the vector by a 2D matrix, according to the formula:

\[ \vec{c} = \vec{a} \cdot M \]

Where \(\vec{a}\) is this vector.

Parameters:

  • matrix (Matrix2D) –

    2D transformation matrix.

Returns:

Examples:

rotation_3 is a transformation matrix that rotates by 90° around the origin. Apply it to a vector like:

>>> Vector3D(1, 0, 0) * rotation_3
Vector3D(0, 1, 0)
__mul__(matrix: Matrix3D) -> Vector3D

Multiply the vector by a 3D matrix, according to the formula:

\[ \vec{c} = \vec{a} \cdot M \]

Where \(\vec{a}\) is this vector.

Parameters:

  • matrix (Matrix3D) –

    3D transformation matrix.

Returns:

Examples:

When rotation_2 is a Matrix3D that rotates around X axis by 90°, apply it to a vector like:

>>> Vector3D(0, 1, 0) * rotation_2
Vector3D(0, 0, 1)

__ne__

__ne__(vec: Vector3D) -> bool

Comparison of vectors without tolerance.

Be careful, this method work without tolerance!

Parameters:

Returns:

  • bool

    True when points are not equal, otherwise false.

__repr__

__repr__() -> str

Convert to string

__sub__

__sub__(vec: Vector3D) -> Vector3D

Subtract two vectors, according to the formula:

\[ \vec{c} = \vec{a} - \vec{b} \]

Where \(\vec{a}\) is this vector.

Parameters:

Returns:

Examples:

>>> Vector3D(1, 2, 3) - Vector3D(4, 5, 6)
Vector3D(-3, -3, -3)

__truediv__

__truediv__(divider: float) -> Vector3D

Divide the vector by a scalar, according to the formula:

\[ \vec{c} = \frac{\vec{a}}{s} \]

Where \(\vec{a}\) is this vector and \(s\) is the scalar.

Parameters:

  • divider (float) –

    scaling divider

Returns:

Examples:

>>> Vector3D(1, 1, 1) / 2
Vector3D(0.5, 0.5, 0.5)
Placeholder