PETRONODE

Object Height by Triangulation



Triangulation

This code solves a typical triangulation task:

1. Use clinometer in your geological compass to measure elevation alpha to the object top.

2. Move towards the object by distance Base.

3. Measure elevation beta to the object top.

4. Optionally measure the ground slope gamma by pointing clinometer to the object bottom.

Elevations above horizon are positive, below - negative.

Download code



    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[0] - tangents[2]

            dt2 = tangents[1] - tangents[2]

            cosGamma = np.cos( np.pi * self.angles[2] / 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[1]

                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[0], self.angles[1]))

                print( "Slope = {:.1f}".format( self.angles[2]))

                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__[0], self.__angleNames__[1], self.__angleNames__[2]))

            self.Solve()

            self.Print()

            return

        def __getInput__(self, question):

            i = 0

            s = str( input( question + " = "))

            ss = s.split(" ")

            try: a = float( ss[0])

            except: a = 1.0

            try: b = float( ss[1])

            except: b = 0.0

            try: c = float( ss[2])

            except: c = 0.0

            try: d = float( ss[3])

            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("")