Vectors

class py123d.geometry.Vector2D[source]

Class to represents 2D vectors, in x, y direction.

Example

>>> from py123d.geometry import Vector2D
>>> v1 = Vector2D(3.0, 4.0)
>>> v2 = Vector2D(1.0, 2.0)
>>> v3 = v1 + v2
>>> v3
Vector2D(4.0, 6.0)
>>> v1.array
array([3., 4.])
>>> v1.magnitude
5.0

Public Data Attributes:

x

The x component of the vector.

y

The y component of the vector.

array

The vector as array of shape (2,), indexed by Vector2DIndex.

magnitude

The magnitude (length) of the 2D vector.

vector_2d

The Vector2D itself.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_array(array[, copy])

Constructs a Vector2D from a numpy array of shape (2,), indexed by Vector2DIndex.

Inherited from ArrayMixin

from_array(array[, copy])

Create an instance from a NumPy array.

from_list(values)

Create an instance from a list of values.

tolist()

Convert the array to a Python list.

to_list()

Convert the array to a Python list.

copy()

Return a copy of the object with a copied array.


__init__(x, y)[source]

Initialize Vector2D with x, y components.

Parameters:
classmethod from_array(array, copy=True)[source]

Constructs a Vector2D from a numpy array of shape (2,), indexed by Vector2DIndex.

Parameters:
  • array (ndarray[tuple[Any, ...], dtype[float64]]) – The array of shape (2,) with the x,y components.

  • copy (bool) – Whether to copy the input array. Defaults to True.

Return type:

Vector2D

Returns:

A Vector2D instance.

property x: float

The x component of the vector.

property y: float

The y component of the vector.

property array: ndarray[tuple[Any, ...], dtype[float64]]

The vector as array of shape (2,), indexed by Vector2DIndex.

property magnitude: float

The magnitude (length) of the 2D vector.

property vector_2d: Vector2D

The Vector2D itself.

copy()

Return a copy of the object with a copied array.

Return type:

ArrayMixin

classmethod from_list(values)

Create an instance from a list of values.

Return type:

Self

Parameters:

values (list)

property shape: tuple

Return the shape of the array.

to_list()

Convert the array to a Python list.

Return type:

list

tolist()

Convert the array to a Python list.

Return type:

list

class py123d.geometry.Vector3D[source]

Class to represents 3D vectors, in x, y, z direction.

Example

>>> from py123d.geometry import Vector3D
>>> v1 = Vector3D(1.0, 2.0, 3.0)
>>> v2 = Vector3D(4.0, 5.0, 6.0)
>>> v3 = v1 + v2
>>> v3
Vector3D(5.0, 7.0, 9.0)
>>> v1.array
array([1., 2., 3.])
>>> v1.magnitude
3.7416573867739413

Public Data Attributes:

x

The x component of the vector.

y

The y component of the vector.

z

The z component of the vector.

array

The vector as array of shape (3,), indexed by Vector3DIndex.

magnitude

The magnitude (length) of the 3D vector.

vector_3d

The Vector3D itself.

vector_2d

The 2D vector projection (x, y) of the 3D vector.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_array(array[, copy])

Constructs a Vector3D from a numpy array of shape (3,), indexed by Vector3DIndex.

Inherited from ArrayMixin

from_array(array[, copy])

Create an instance from a NumPy array.

from_list(values)

Create an instance from a list of values.

tolist()

Convert the array to a Python list.

to_list()

Convert the array to a Python list.

copy()

Return a copy of the object with a copied array.


__init__(x, y, z)[source]

Initialize Vector3D with x, y, z components.

Parameters:
classmethod from_array(array, copy=True)[source]

Constructs a Vector3D from a numpy array of shape (3,), indexed by Vector3DIndex.

Parameters:
  • array (ndarray[tuple[Any, ...], dtype[float64]]) – The array of shape (3,) with the x,y,z components.

  • copy (bool) – Whether to copy the input array. Defaults to True.

Return type:

Vector3D

Returns:

A Vector3D instance.

property x: float

The x component of the vector.

property y: float

The y component of the vector.

property z: float

The z component of the vector.

property array: ndarray[tuple[Any, ...], dtype[float64]]

The vector as array of shape (3,), indexed by Vector3DIndex.

property magnitude: float

The magnitude (length) of the 3D vector.

property vector_3d: Vector3D

The Vector3D itself.

property vector_2d: Vector2D

The 2D vector projection (x, y) of the 3D vector.

copy()

Return a copy of the object with a copied array.

Return type:

ArrayMixin

classmethod from_list(values)

Create an instance from a list of values.

Return type:

Self

Parameters:

values (list)

property shape: tuple

Return the shape of the array.

to_list()

Convert the array to a Python list.

Return type:

list

tolist()

Convert the array to a Python list.

Return type:

list