  Height by Triangulation (Python 3.x)   Determines an object height from three geological compass inclination measurements and one base distance This code solves a classic triangulation task. Elevations above the horizon are positive, below - negative. 1. Use the compass clinometer to measure elevation $$\alpha$$ to the object’s top; 2. Move towards the object by distance Base; 3. Measure elevation $$\beta$$ to the object’s top; 4. Optionally measure the ground slope $$\gamma$$ by pointing clinometer to the object’s bottom (on a horizontal ground use zero); 5. Don't forget to add your "eye-height" h.   Download source code: Triangulation_Height.py   import numpy as np class TriangulationHeight: def __init__( self, base = 1.0, a = [0.0,0.0,0.0]): self.__angleNames__ = ['alpha', 'beta', 'gamma'] self.Base = base self.angles = np.array( a) self.Verbose = False self.Solve() return def Solve( self): tangents = np.pi * self.angles / 180.0 tangents = np.tan( tangents) dt1 = tangents - tangents dt2 = tangents - tangents cosGamma = np.cos( np.pi * self.angles / 180.0) try: a = dt1 * dt2 b = dt2 - dt1 if a == 0.0 and b == 0.0: self.Height = 0.0 self.Distance = -999.25 if self.Verbose: print( "Distance undefined") return self.Height = self.Base * a / b self.Distance = self.Height / tangents self.Height *= cosGamma except: if self.Verbose: print( "Incorrect input data") self.Height = -999.25 self.Distance = -999.25 return def Print( self): if self.Verbose: print( "Base = {:.3f}".format( self.Base)) print( "Angles = {:.1f} and {:.1f}".format( self.angles, self.angles)) print( "Slope = {:.1f}".format( self.angles)) print( "Solution:") print( "Height = {:.3f}".format( self.Height)) print( "Distance = {:.3f}".format( self.Distance)) return def SolveInteractive( self): self.Base, self.angles = self.__getInput__( "Base {:s} {:s} {:s}".format( self.__angleNames__, self.__angleNames__, self.__angleNames__)) self.Solve() self.Print() return def __getInput__(self, question): i = 0 s = str( input( question + " = ")) ss = s.split(" ") try: a = float( ss) except: a = 1.0 try: b = float( ss) except: b = 0.0 try: c = float( ss) except: c = 0.0 try: d = float( ss) except: d = 0.0 return a, np.array( [b,c,d]) ## ## Uncomment for testing ## ##print( "Test complete data") ##T = TriangulationHeight(30.0, [10.0,17.0,-8.0]) ##T.Print() ## ##print( "\nTest incomplete data") ##T.angles = np.array([-8.0,-8.0,-8.0]) ##T.Solve() ##T.Print() ## print( "Triangulation for object height.\nUse positive angles above horizon and neqative below.\nSend Control-C to stop.\n") T = TriangulationHeight() T.Verbose = True while True: T.SolveInteractive() print("") (C) M.Yakimov, 2006 