Python - Calculate Distance to an Object Using Triangulation With Trigonometry
by matt392 in Circuits > Software
67 Views, 1 Favorites, 0 Comments
Python - Calculate Distance to an Object Using Triangulation With Trigonometry


print ("This program will calculate Distance to Object using Triangulation with Trigonometry.") import math ### Formula for calculating the Distance using Triangulation with Trigonometry: # DistanceToObject = (DistanceBetweenTwoPoints * sin(AnglePointOne) * sin(AnglePointTwo))/(sin(AnglePointOne+AnglePointTwo) ) ############################################################################### # Enter the DistanceBetweenTwoPoints, AnglePointOne, AnglePointTwo ContinueCalculations = "y" def CalculateDistanceToObject(): print ("Calculating the Distance to an Object.") # Enter the DistanceBetweenTwoPoints DistanceBetweenTwoPoints = float(input("Enter the Distance Between Two Points: ") ) # Enter the AnglePointOne AnglePointOne = float(input("Enter the Angle at Point One: ") ) # Enter the AnglePointTwo AnglePointTwo = float(input("Enter the Angle at Point Two: ") ) # Convert degrees to radians # Python trig functions take radians # Use math.radians() function to convert degrees to radians AnglePointOneInRadians = math.radians(AnglePointOne) AnglePointTwoinRadians = math.radians(AnglePointTwo) # Calculate the top of the fraction TopOfFraction = (DistanceBetweenTwoPoints * math.sin(AnglePointOneInRadians) * math.sin(AnglePointTwoinRadians) ) print ("Top of Fraction is: ", TopOfFraction) # Calculate the bottom of the fraction AngleSum = AnglePointOne+AnglePointTwo AngleSumInRadians = math.radians(AngleSum) BottomOfFraction = (math.sin(AngleSumInRadians)) # Calculate the fraction DistanceToObject = TopOfFraction/BottomOfFraction print("The Distance to Object is: ", DistanceToObject) while (ContinueCalculations=="y"): CalculateDistanceToObject() ContinueCalculations = str(input("Would you like to continue to calculate the Distance to Object? (y/n): ")) print("==================================") print ("Thank you to www.MapleSoft.com for assistance with this formula.")