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()
.
- class tensorbay.geometry.polyline.Polyline2D(points: Optional[Iterable[Iterable[float]]] = None)[source]¶
Bases:
tensorbay.geometry.polygon.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}]