January 19, 2010 9:00 AM
[ We studied methods of computing sines in a previous exercise. In today’s exercise, guest author Jos Koot, a retired physicist, amateur pilot, and Scheme enthusiast, gives us an example of the use of sines. Feel free to contact me if you have an idea for an exercise, or if you wish to contribute your own exercise. Jos writes this disclaimer: Do not use the example program for real life flight planning. It may not be fool proof!!! Use more appropriate equipment and procedures after studying aeronautics more profoundly. I do not accept any claims. There is a lot more to flying than presented in this exercise. ]
When preparing to fly, a pilot must know:
Directions are measured in degrees clockwise from geographic north, 360 degrees on the compass-card. You may measure distances and times in any unit you like. Speeds should be in unit of distance per unit of time, of course. We take the air speed as a given datum and we ignore time needed for climbing and descending. Because the plane may be drifted by the wind, the pilot must calculate which direction to head for in order to compensate the drift. For this purpose the pilot may draw a triangle whose sides are speeds:
It is instructive first to draw some navigation triangles by means of a pair of compasses and a ruler. The air speed is significantly greater than the wind speed, of course. First draw a line in the direction of the ground track. On this line choose a point B. Draw the drift ending in point B. Now we have point C. Draw a circle with point C for its centre and the air speed for its radius. The circle has two points of intersection with the ground track. One of the intersection points is A. Point A and the other point of intersection correspond to the two roots of the quadratic equation. Because the ground speed is directed from point A to point B it is not difficult to see which point of intersection is the right one. Now the vector equation AB = AC + CB is satisfied.
The known data are: ground track GT, distance (D) from departure to destination, wind name WN, wind velocity WS and the air speed AS. The air speed is significantly greater than the velocity of the wind, of course. From these data we want to compute: true heading TH, ground speed GS and time of the flight (FT=D/GS).
One solution uses the law of sines, which states that the ratio of the length of a side to the sine of the opposite angle is the same for all three sides of any triangle. We have , hence
. The ground speed can be calculated as
.
Another solution uses the cosine rule c² = a² + b² – 2ab cos(θ) to compute the third side of a triangle when two sides and the included angle are known, a quadratic equation is obtained. Solving this equation for the unknown ground speed, we have . Because we want a positive ground speed, take the root with the plus sign. Finally use the cosine rule again in order to compute the angle of correction (angle A), which is the angle between the ground track and the required true heading:
, so the true heading is
. This angle must be added or subtracted from the direction of the ground track depending on which side the wind drifts the plane.
Your task is to write two functions, as above, that take a distance, ground track, wind speed and direction, and air speed and computes the true heading, ground speed, correction and duration of flight. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
Posted by programmingpraxis
Categories: Exercises
Tags:
Mobile Site | Full Site
Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.
[…] Praxis – Flight Planning By Remco Niemeijer In today’s Programming Praxis exercise we have to implement two algorithms for flight […]
By Programming Praxis – Flight Planning « Bonsai Code on January 19, 2010 at 10:17 AM
My Haskell solution (see http://bonsaicode.wordpress.com/2010/01/19/programming-praxis-flight-planning/ for a version with comments):
import Data.Fixed toDeg, toRad :: Floating a => a -> a toDeg d = d * 180 / pi toRad d = d * pi / 180 navigate1 :: Float -> Float -> Float -> Float -> Float -> [Int] navigate1 d gt wn ws as = map round [gs, a, th, ft] where b = toRad $ gt - wn + 180 a = toDeg $ asin (ws * sin b / as) th = mod' (gt + a) 360 gs = (cos . toRad $ th - gt) * as + ws * cos b ft = d / gs * 60 navigate2 :: Float -> Float -> Float -> Float -> Float -> [Int] navigate2 d gt wn ws as = if det < 0 || gs < 0 then error "strange" else map round [gs, a, th, ft] where b = mod' (gt - wn + 180) 360 x = ws * cos (toRad b) det = x^2 - ws^2 + as^2 gs = x + sqrt det a = (if b < 180 then id else negate) . toDeg . acos $ (as^2 + gs^2 - ws^2) / (2 * gs * as) th = gt + a ft = d / gs * 60By Remco Niemeijer on January 19, 2010 at 10:17 AM