Debian Codegraph @

examples/01-filter/geodesic.py

raw
1 """
2 .. _geodesic_example:
3
4 Geodesic Paths
5 ~~~~~~~~~~~~~~
6
7 Calculates the geodesic path between two vertices using Dijkstra's algorithm
8 """
9
10 # sphinx_gallery_thumbnail_number = 1
11 import pyvista as pv
12 from pyvista import examples
13
14 # Load a global topography surface and decimate it
15 land = examples.download_topo_land().triangulate().decimate(0.98)
16
17 # %%
18 # Get the geodesic path as a new :class:`pyvista.PolyData` object:
19 cape_town = land.find_closest_point((0.790801, 0.264598, -0.551942))
20 dubai = land.find_closest_point((0.512642, 0.745898, 0.425255))
21 bangkok = land.find_closest_point((-0.177077, 0.955419, 0.236273))
22 rome = land.find_closest_point((0.718047, 0.163038, 0.676684))
23
24 a = land.geodesic(cape_town, dubai)
25 b = land.geodesic(cape_town, bangkok)
26 c = land.geodesic(cape_town, rome)
27
28 # %%
29 # Render the path along the land surface
30
31 pl = pv.Plotter()
32 pl.add_mesh(a + b + c, line_width=10, color='red', label='Geodesic Path')
33 pl.add_mesh(land, show_edges=True)
34 pl.add_legend()
35 pl.camera_position = pv.CameraPosition(
36 position=(3.5839785524183934, 2.3915238111304924, 1.3993738227478327),
37 focal_point=(-0.06842917033182638, 0.15467201157962263, -0.07331693636555875),
38 viewup=(-0.34851770951584765, -0.04724188391065845, 0.9361108965066047),
39 )
40
41 pl.show()
42
43 # %%
44 # How long is that path?
45 distance = land.geodesic_distance(cape_town, rome)
46 distance
47 # %%
48 # .. tags:: filter