PETRONODE

Remote Object Size 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. Measure elevation beta to the object bottom.

3. Move towards the object by distance Base.

4. Measure elevation gamma to the object bottom.

Elevations above horizon are positive, below - negative.

Download code



    import numpy as np

    

    class TriangulationSize:

        def __init__( self, base = 1.0, a = [5.0,4.0,8.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[2] - tangents[1]

            try:

                if dt1 <= 0.0:

                    if self.Verbose: print( "Incorrect input data")

                    self.Distance = -999.25

                    self.Height = -999.25

                    self.Size = -999.25

                    return

                self.Distance = self.Base * tangents[1] / dt1

                self.Height = self.Distance * tangents[2]

                self.Size = (self.Distance+self.Base) * tangents[0]

                self.Size -= self.Height

            except:

                if self.Verbose: print( "Incorrect input data")

                self.Distance = -999.25

                self.Height = -999.25

                self.Size = -999.25

            return

        def Print( self):

            if self.Verbose:

                print( "Base = {:.3f}".format( self.Base))

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

                print( "Solution:")

            print( "Distance = {:.3f}".format( self.Distance))

            print( "Height = {:.3f}".format( self.Height))

            print( "Size = {:.3f}".format( self.Size))

            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 = TriangulationSize(30.0, [12.0,10.0,17.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 = TriangulationSize()

    T.Verbose = True

    while True:

        T.SolveInteractive()

        print("")