Polylines

class py123d.geometry.Polyline2D[source]

Represents a interpolatable 2D polyline.

Example

>>> import numpy as np
>>> from py123d.geometry import Polyline2D
>>> polyline = Polyline2D.from_array(np.array([[0.0, 0.0], [1.0, 1.0], [2.0, 0.0]]))
>>> polyline.length
2.8284271247461903
>>> polyline.interpolate(np.sqrt(2))
Point2D(array=[1. 1.])

Public Data Attributes:

linestring

The shapely LineString representation of the polyline.

array

The numpy array representation of shape (N, 2), indexed by Point2DIndex.

polyline_se2

The PolylineSE2 representation of the polyline, with inferred yaw angles.

length

Returns the length of the polyline.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_linestring(linestring)

Creates a Polyline2D from a Shapely LineString.

from_array(array[, copy])

Creates a Polyline2D from a (N, 2) or (N, 3) shaped numpy array.

interpolate(distances[, normalized])

Interpolates the Polyline2D at the given distances.

project(point[, normalized])

Projects a point onto the polyline and returns the distance along the polyline to the closest point.

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.


classmethod from_linestring(linestring)[source]

Creates a Polyline2D from a Shapely LineString. If the LineString has Z-coordinates, they are ignored.

Parameters:

linestring (LineString) – A shapely LineString object.

Return type:

Polyline2D

Returns:

A Polyline2D instance.

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

Creates a Polyline2D from a (N, 2) or (N, 3) shaped numpy array. Assumes […,:2] slices are XY coordinates.

Parameters:
Raises:

ValueError – If the input array is not of the expected shape.

Return type:

Polyline2D

Returns:

A Polyline2D instance.

property linestring: LineString

The shapely LineString representation of the polyline.

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

The numpy array representation of shape (N, 2), indexed by Point2DIndex.

property polyline_se2: PolylineSE2

The PolylineSE2 representation of the polyline, with inferred yaw angles.

property length: float

Returns the length of the polyline.

interpolate(distances, normalized=False)[source]

Interpolates the Polyline2D at the given distances.

Parameters:
Return type:

Union[Point2D, ndarray[tuple[Any, ...], dtype[float64]]]

Returns:

The interpolated point(s) on the polyline.

project(point, normalized=False)[source]

Projects a point onto the polyline and returns the distance along the polyline to the closest point.

Parameters:
  • point (Union[Point, Point2D, PoseSE2, ndarray[tuple[Any, ...], dtype[float64]]]) – The point to project onto the polyline.

  • normalized (bool) – Whether to return the normalized distance, defaults to False.

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

The distance along the polyline to the closest point.

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.PolylineSE2[source]

Represents a interpolatable SE2 polyline.

Example

>>> import numpy as np
>>> from py123d.geometry import PolylineSE2
>>> polyline_se2 = PolylineSE2.from_array(np.array([[0.0, 0.0, 0.0], [1.0, 1.0, np.pi/4], [2.0, 0.0, 0.0]]))
>>> polyline_se2.length
2.8284271247461903
>>> polyline_se2.interpolate(np.sqrt(2))
PoseSE2(array=[1.         1.         0.78539816])

Public Data Attributes:

linestring

The shapely LineString representation of the polyline.

array

The numpy array representation of shape (N, 3), indexed by PoseSE2Index.

length

Returns the length of the polyline.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_linestring(linestring)

Creates a PolylineSE2 from a shapely LineString.

from_array(polyline_array)

Creates a PolylineSE2 from a numpy array.

interpolate(distances[, normalized])

Interpolates the polyline at the given distances.

project(point[, normalized])

Projects a point onto the polyline and returns the distance along the polyline to the closest point.

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.


classmethod from_linestring(linestring)[source]

Creates a PolylineSE2 from a shapely LineString. The yaw angles are inferred from the LineString coordinates.

Parameters:

linestring (LineString) – The LineString to convert.

Return type:

PolylineSE2

Returns:

A PolylineSE2 representing the same path as the LineString.

classmethod from_array(polyline_array)[source]

Creates a PolylineSE2 from a numpy array.

Parameters:

polyline_array (ndarray[tuple[Any, ...], dtype[float32]]) – The input numpy array representing, either indexed by Point2DIndex or PoseSE2Index.

Raises:

ValueError – If the input array is not of the expected shape.

Return type:

PolylineSE2

Returns:

A PolylineSE2 representing the same path as the input array.

property linestring: LineString

The shapely LineString representation of the polyline.

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

The numpy array representation of shape (N, 3), indexed by PoseSE2Index.

property length: float

Returns the length of the polyline.

interpolate(distances, normalized=False)[source]

Interpolates the polyline at the given distances.

Parameters:
  • distances (Union[float, ndarray[tuple[Any, ...], dtype[float64]]]) – The distances along the polyline to interpolate.

  • normalized (bool) – Whether the distances are normalized (0 to 1), defaults to False

Return type:

Union[PoseSE2, ndarray[tuple[Any, ...], dtype[float64]]]

Returns:

The interpolated StateSE2 or an array of interpolated states, according to

project(point, normalized=False)[source]

Projects a point onto the polyline and returns the distance along the polyline to the closest point.

Parameters:
  • point (Union[Point, Point2D, PoseSE2, ndarray[tuple[Any, ...], dtype[float64]]]) – The point to project onto the polyline.

  • normalized (bool) – Whether to return the normalized distance, defaults to False.

Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

The distance along the polyline to the closest point.

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.Polyline3D[source]

Represents a interpolatable 3D polyline.

Example

>>> import numpy as np
>>> from py123d.geometry import Polyline3D
>>> polyline_3d = Polyline3D.from_array(np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [2.0, 0.0, 0.0]]))
>>> polyline_3d.length
3.4641016151377544
>>> polyline_3d.interpolate(np.sqrt(3))
Point3D(array=[1. 1. 1.])

Public Data Attributes:

linestring

The shapely LineString representation of the 3D polyline.

array

The numpy array representation of shape (N, 3), indexed by Point3DIndex.

polyline_2d

The Polyline2D representation of the 3D polyline.

polyline_se2

The PolylineSE2 representation of the 3D polyline.

length

Returns the length of the 3D polyline.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_linestring(linestring)

Creates a Polyline3D from a shapely LineString.

from_array(array)

Creates a Polyline3D from a numpy array.

interpolate(distances[, normalized])

Interpolates the 3D polyline at the given distances.

project(point[, normalized])

Projects a point onto the 3D polyline and returns the distance along the polyline to the closest point.

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.


classmethod from_linestring(linestring)[source]

Creates a Polyline3D from a shapely LineString. If the LineString does not have Z-coordinates, the coordinate is zero-padded.

Parameters:

linestring (LineString) – The input LineString.

Return type:

Polyline3D

Returns:

A Polyline3D instance.

classmethod from_array(array)[source]

Creates a Polyline3D from a numpy array.

Parameters:

array (ndarray[tuple[Any, ...], dtype[float64]]) – A numpy array of shape (N, 3) representing 3D points, e.g. indexed by Point3DIndex.

Return type:

Polyline3D

Returns:

A Polyline3D instance.

property linestring: LineString

The shapely LineString representation of the 3D polyline.

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

The numpy array representation of shape (N, 3), indexed by Point3DIndex.

property polyline_2d: Polyline2D

The Polyline2D representation of the 3D polyline.

property polyline_se2: PolylineSE2

The PolylineSE2 representation of the 3D polyline.

property length: float

Returns the length of the 3D polyline.

interpolate(distances, normalized=False)[source]

Interpolates the 3D polyline at the given distances.

Parameters:
  • distances (Union[float, ndarray[tuple[Any, ...], dtype[float64]]]) – A float or numpy array of distances along the polyline.

  • normalized (bool) – Whether to interpret the distances as fractions of the length.

Return type:

Union[Point3D, ndarray[tuple[Any, ...], dtype[float64]]]

Returns:

A Point3D instance or a numpy array of shape (N, 3) representing the interpolated points.

project(point, normalized=False)[source]

Projects a point onto the 3D polyline and returns the distance along the polyline to the closest point.

Parameters:
Return type:

ndarray[tuple[Any, ...], dtype[float64]]

Returns:

The distance along the polyline to the closest point.

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