Debian Codegraph @

examples/02-plot/distance_measurement.py

raw
1 """
2 .. _distance_measurement_example:
3
4 Measuring distance
5 ~~~~~~~~~~~~~~~~~~
6 This example demonstrates how to measure distance between two points.
7 :func:`add_measurement_widget() <pyvista.Plotter.add_measurement_widget>`.
8
9 """
10
11 import pyvista as pv
12
13 cube = pv.Cube()
14 cube2 = pv.Cube(center=[10, 10, 0])
15
16 pl = pv.Plotter()
17 pl.add_mesh(cube)
18 pl.add_mesh(cube2)
19
20
21 def callback(a, b, distance): # noqa: ARG001
22 pl.add_text(f'Distance: {distance:.2f}', name='dist')
23
24
25 pl.add_measurement_widget(callback)
26 pl.show()
27 # %%
28 # .. tags:: plot