Python Line of Sight Calculator

Originally published December 21, 2020 on my earlier blog; republished as written. Images from the original are not carried over.

In learning machine learning and Python, I created a mini-project to help determine the Python language and the math behind it. Using this code, I can calculate my line of sight to a point on the ground.

import math from math import sqrt

a = int(input("What is the Altitude of the aircraft in feet? ")) b = int(input("What is the distance from the target in Nautical Miles? ")) b = b * 6076.12 c = sqrt(a*a + b*b) c = c / 6076.12 c = c * 6076.12

# Angles angle1 = math.asin(a/c) * 180/math.pi angle2 = math.asin(b/c) * 180/math.pi angle3 = 180 - angle1 - angle2 angle4 = math.asin(a/c)

distance = int(input("What is the distance to the closest high terrain from your target in NM ")) distance1 = distance distance = distance * 6076.12

height_at_distance = distance * (math.atan(angle4)) height_at_distance = int(height_at_distance) print("At the distance of", str(distance1), "NM, your line of sight is at", str(height_at_distance) + " ft.", "\nIf there is terrain within", str(distance1), "NM of the target that is taller than", str(height_at_distance), "ft, \nyou can't see the target.")

← All writing