tensorbay.geometry.polyline
Polyline2D.
Polyline2D
contains the coordinates of the vertexes of the polyline
and provides a series of methods to operate on polyline, such as
Polyline2D.uniform_frechet_distance()
and Polyline2D.similarity()
.
MultiPolyline2D
contains a list of polyline.
- class tensorbay.geometry.polyline.Polyline2D(points: Optional[Iterable[Iterable[float]]] = None)[source]
Bases:
tensorbay.geometry.point_list.PointList2D
[tensorbay.geometry.vector.Vector2D
]This class defines the concept of Polyline2D.
Polyline2D
contains the coordinates of the vertexes of the polyline and provides a series of methods to operate on polyline, such asPolyline2D.uniform_frechet_distance()
andPolyline2D.similarity()
.Examples
>>> Polyline2D([[1, 2], [2, 3]]) Polyline2D [ Vector2D(1, 2), Vector2D(2, 3) ]
- static uniform_frechet_distance(polyline1: Sequence[Sequence[float]], polyline2: Sequence[Sequence[float]]) float [source]
Compute the maximum distance between two curves if walk on a constant speed on a curve.
- Parameters
polyline1 – The first polyline consists of multiple points.
polyline2 – The second polyline consists of multiple points.
- Returns
The computed distance between the two polylines.
Examples
>>> polyline_1 = [[1, 1], [1, 2], [2, 2]] >>> polyline_2 = [[4, 5], [2, 1], [3, 3]] >>> Polyline2D.uniform_frechet_distance(polyline_1, polyline_2) 3.605551275463989
- static similarity(polyline1: Sequence[Sequence[float]], polyline2: Sequence[Sequence[float]]) float [source]
Calculate the similarity between two polylines, range from 0 to 1.
- Parameters
polyline1 – The first polyline consists of multiple points.
polyline2 – The second polyline consisting of multiple points.
- Returns
The similarity between the two polylines. The larger the value, the higher the similarity.
Examples
>>> polyline_1 = [[1, 1], [1, 2], [2, 2]] >>> polyline_2 = [[4, 5], [2, 1], [3, 3]] >>> Polyline2D.similarity(polyline_1, polyline_2) 0.2788897449072022
- classmethod loads(contents: List[Dict[str, float]]) tensorbay.geometry.polyline._P [source]
Load a
Polyline2D
from a list of dict.- Parameters
contents – A list of dict containing the coordinates of the vertexes of the polyline.
- Returns
The loaded
Polyline2D
object.
Examples
>>> polyline = Polyline2D([[1, 1], [1, 2], [2, 2]]) >>> polyline.dumps() [{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}]
- class tensorbay.geometry.polyline.MultiPolyline2D(polylines: Optional[Iterable[Iterable[Iterable[float]]]] = None)[source]
Bases:
tensorbay.geometry.point_list.MultiPointList2D
[tensorbay.geometry.polyline.Polyline2D
]This class defines the concept of MultiPolyline2D.
MultiPolyline2D
contains a list of polylines.- Parameters
polylines – A list of polylines.
Examples
>>> MultiPolyline2D([[[1, 2], [2, 3]], [[3, 4], [6, 8]]]) MultiPolyline2D [ Polyline2D [...] Polyline2D [...] ... ]
- classmethod loads(contents: List[List[Dict[str, float]]]) tensorbay.geometry.polyline._P [source]
Loads a
MultiPolyline2D
from the given contents.- Parameters
contents – A list of dict lists containing the coordinates of the vertexes of the polyline list.
- Returns
The loaded
MultiPolyline2D
object.
Examples
>>> contents = [[{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}], [{'x': 2, 'y': 3}, {'x': 3, 'y': 5}]] >>> multipolyline = MultiPolyline2D.loads(contents) >>> multipolyline MultiPolyline2D [ Polyline2D [...] Polyline2D [...] ... ]
- dumps() List[List[Dict[str, float]]] [source]
Dumps a
MultiPolyline2D
into a polyline list.- Returns
All the information of the
MultiPolyline2D
.
Examples
>>> multipolyline = MultiPolyline2D([[[1, 1], [1, 2], [2, 2]], [[2, 3], [3, 5]]]) >>> multipolyline.dumps() [ [{'x': 1, 'y': 1}, {'x': 1, 'y': 2}, {'x': 2, 'y': 2}], [{'x': 2, 'y': 3}, {'x': 3, 'y': 5}] ]