geodesic#

PolyDataFilters.geodesic(start_vertex, end_vertex, inplace=False, keep_order=True, use_scalar_weights=False, progress_bar=False)[source]#

Calculate the geodesic path between two vertices using Dijkstra’s algorithm.

This will add an array titled 'vtkOriginalPointIds' of the input mesh’s point ids to the output mesh. The default behavior of the underlying vtkDijkstraGraphGeodesicPath filter is that the geodesic path is reversed in the resulting mesh. This is overridden in PyVista by default.

Parameters:
start_vertexint

Vertex index indicating the start point of the geodesic segment.

end_vertexint

Vertex index indicating the end point of the geodesic segment.

inplacebool, optional

Whether the input mesh should be replaced with the path. The geodesic path is always returned.

keep_orderbool, optional

If True, the points of the returned path are guaranteed to start with the start vertex (as opposed to the end vertex).

New in version 0.32.0.

use_scalar_weightsbool, optional

If True, use scalar values in the edge weight (only supported with VTK>=9). This only works for point data.

progress_barbool, optional

Display a progress bar to indicate progress.

Returns:
pyvista.PolyData

PolyData object consisting of the line segment between the two given vertices. If inplace is True this is the same object as the input mesh.

Examples

Plot the path between two points on the random hills mesh.

>>> import pyvista as pv
>>> from pyvista import examples
>>> hills = examples.load_random_hills()
>>> path = hills.geodesic(560, 5820)
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(hills)
>>> _ = pl.add_mesh(path, line_width=5, color='k')
>>> pl.show()
../../../_images/pyvista-PolyDataFilters-geodesic-1_00_00.png

See Geodesic Paths for more examples using this filter.