Python example: lines-3d-geometry-example.py
3D lines and points: construction and point-to-line distance with mrpt.math.
Modules: mrpt.math
1#!/usr/bin/env python3
2"""
33D lines and points: construction and point-to-line distance with mrpt.math.
4"""
5
6from mrpt.math import TPoint3D, TLine3D
7
8l1: TLine3D = TLine3D.FromTwoPoints(TPoint3D(0, 0, 0), TPoint3D(1, 0, 0))
9l2: TLine3D = TLine3D.FromTwoPoints(TPoint3D(1, 1, 1), TPoint3D(2, 2, 0))
10
11print('l1 : ' + str(l1))
12print('l2 : ' + str(l2))
13
14# Distance from l1 to a point (the line-to-line distance function of
15# mrpt/math/geometry.h is not wrapped yet):
16pt = TPoint3D(0, 1, 0)
17print('dist(l1, pt) : ' + str(l1.distance(pt)))
18
19# Director vector is a plain list [dx, dy, dz]:
20print('l1.director : ' + str(l1.director))
Output:
l1 : P=[ 0.00000, 0.00000, 0.00000] u=[ 1.00000, 0.00000, 0.00000]
l2 : P=[ 1.00000, 1.00000, 1.00000] u=[ 1.00000, 1.00000, -1.00000]
dist(l1, pt) : 1.0
l1.director : [1.000000 0.000000 0.000000]