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:
linestringThe shapely LineString representation of the polyline.
arrayThe numpy array representation of shape (N, 2), indexed by
Point2DIndex.polyline_se2The
PolylineSE2representation of the polyline, with inferred yaw angles.lengthReturns the length of the polyline.
Inherited from
ArrayMixinarrayThe array representation of the geometric entity.
shapeReturn the shape of the array.
Public Methods:
from_linestring(linestring)Creates a
Polyline2Dfrom a Shapely LineString.from_array(array[, copy])Creates a
Polyline2Dfrom a (N, 2) or (N, 3) shaped numpy array.interpolate(distances[, normalized])Interpolates the
Polyline2Dat 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
ArrayMixinfrom_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
Polyline2Dfrom a Shapely LineString. If the LineString has Z-coordinates, they are ignored.- Parameters:
linestring (
LineString) – A shapely LineString object.- Return type:
- Returns:
A Polyline2D instance.
- classmethod from_array(array, copy=True)[source]¶
Creates a
Polyline2Dfrom a (N, 2) or (N, 3) shaped numpy array. Assumes […,:2] slices are XY coordinates.- Parameters:
polyline_array – A numpy array of shape (N, 2) or (N, 3), e.g. indexed by
Point2DIndexorPoint3DIndex.copy (bool)
- Raises:
ValueError – If the input array is not of the expected shape.
- Return type:
- Returns:
A
Polyline2Dinstance.
- 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
PolylineSE2representation of the polyline, with inferred yaw angles.
- interpolate(distances, normalized=False)[source]¶
Interpolates the
Polyline2Dat the given distances.
- project(point, normalized=False)[source]¶
Projects a point onto the polyline and returns the distance along the polyline to the closest point.
- Parameters:
- Return type:
- Returns:
The distance along the polyline to the closest point.
- copy()¶
Return a copy of the object with a copied array.
- Return type:
ArrayMixin
- 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:
linestringThe shapely LineString representation of the polyline.
arrayThe numpy array representation of shape (N, 3), indexed by
PoseSE2Index.lengthReturns the length of the polyline.
Inherited from
ArrayMixinarrayThe array representation of the geometric entity.
shapeReturn the shape of the array.
Public Methods:
from_linestring(linestring)Creates a
PolylineSE2from a shapely LineString.from_array(polyline_array)Creates a
PolylineSE2from 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
ArrayMixinfrom_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
PolylineSE2from a shapely LineString. The yaw angles are inferred from the LineString coordinates.- Parameters:
linestring (
LineString) – The LineString to convert.- Return type:
- Returns:
A
PolylineSE2representing the same path as the LineString.
- classmethod from_array(polyline_array)[source]¶
Creates a
PolylineSE2from a numpy array.- Parameters:
polyline_array (
ndarray[tuple[Any,...],dtype[float32]]) – The input numpy array representing, either indexed byPoint2DIndexorPoseSE2Index.- Raises:
ValueError – If the input array is not of the expected shape.
- Return type:
- Returns:
A
PolylineSE2representing 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.
- interpolate(distances, normalized=False)[source]¶
Interpolates the polyline at the given distances.
- Parameters:
- Return type:
- 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:
- Return type:
- Returns:
The distance along the polyline to the closest point.
- copy()¶
Return a copy of the object with a copied array.
- Return type:
ArrayMixin
- 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:
linestringThe shapely LineString representation of the 3D polyline.
arrayThe numpy array representation of shape (N, 3), indexed by
Point3DIndex.polyline_2dThe
Polyline2Drepresentation of the 3D polyline.polyline_se2The
PolylineSE2representation of the 3D polyline.lengthReturns the length of the 3D polyline.
Inherited from
ArrayMixinarrayThe array representation of the geometric entity.
shapeReturn the shape of the array.
Public Methods:
from_linestring(linestring)Creates a
Polyline3Dfrom a shapely LineString.from_array(array)Creates a
Polyline3Dfrom 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
ArrayMixinfrom_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
Polyline3Dfrom a shapely LineString. If the LineString does not have Z-coordinates, the coordinate is zero-padded.- Parameters:
linestring (
LineString) – The input LineString.- Return type:
- Returns:
A
Polyline3Dinstance.
- classmethod from_array(array)[source]¶
Creates a
Polyline3Dfrom a numpy array.- Parameters:
array (
ndarray[tuple[Any,...],dtype[float64]]) – A numpy array of shape (N, 3) representing 3D points, e.g. indexed byPoint3DIndex.- Return type:
- Returns:
A
Polyline3Dinstance.
- 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
Polyline2Drepresentation of the 3D polyline.
- property polyline_se2: PolylineSE2¶
The
PolylineSE2representation of the 3D polyline.
- interpolate(distances, normalized=False)[source]¶
Interpolates the 3D polyline at the given distances.
- Parameters:
- Return type:
- 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:
- Returns:
The distance along the polyline to the closest point.
- copy()¶
Return a copy of the object with a copied array.
- Return type:
ArrayMixin