Flight Planning

January 19, 2010

About these ads

Pages: 1 2

2 Responses to “Flight Planning”

  1. […] Praxis – Flight Planning By Remco Niemeijer In today’s Programming Praxis exercise we have to implement two algorithms for flight […]

  2. Remco Niemeijer said

    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 * 60
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 661 other followers

%d bloggers like this: