Python example: lines-3d-geometry-example.py

This example illustrates some geometry functions:

 1#!/usr/bin/env python3
 2
 3# ---------------------------------------------------------------------
 4# Install python3-pymrpt, ros-$ROS_DISTRO-mrpt2, or test with a local build with:
 5# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH
 6# ---------------------------------------------------------------------
 7
 8from mrpt.pymrpt import mrpt
 9
10# Aliases:
11TPoint3D = mrpt.math.TPoint3D_double_t
12TLine3D = mrpt.math.TLine3D
13
14l1: TLine3D = TLine3D.FromTwoPoints(TPoint3D(0, 0, 0), TPoint3D(1, 0, 0))
15l2: TLine3D = TLine3D.FromTwoPoints(TPoint3D(1, 1, 1), TPoint3D(2, 2, 0))
16
17print('l1             : ' + str(l1))
18print('l2             : ' + str(l2))
19print('dist(l1,l2)    : ' + str(mrpt.math.distance(l1, l2)))
20print('l1.director    : ' + l1.getDirectorVector().asString())

Output:

1l1             : P=[   0.00000,    0.00000,    0.00000] u=[   1.00000,    0.00000,    0.00000]
2l2             : P=[   1.00000,    1.00000,    1.00000] u=[   1.00000,    1.00000,   -1.00000]
3dist(l1,l2)    : 1.414213562373095