Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created June 28, 2009 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eklitzke/137408 to your computer and use it in GitHub Desktop.
Save eklitzke/137408 to your computer and use it in GitHub Desktop.
type Point = (Double, Double)
type Vector = Point
distance :: Point -> Point -> Double
distance (x1, y1), (x2, y2) = sqrt ((x2-x1)**2 + (y2-y1)**2)
-- Compute the normalized tangent vector from two points
normalizedVector :: Point -> Point -> Vector
normalizedVector (x1, y1) (x2, y1) = (xv / l, yv / l)
where
xv = x2 - x1
yv = y2 - y1
l = distance (0, 0) (xv, yv)
mu :: Double
mu = 6.67428e-11 * 6.0e24
times :: Double -> Vector -> Vector
times v (x, y) = (v*x, v*y)
-- vec is the result of computing normalizedVector on the first two points that
-- were observed (don't fire the rockets before observing!)
delta1 :: Double -> Double -> Vector -> Vector
delta1 r1 r2 vec = (lhs*rhs) `times` vec
where
lhs = sqrt (mu / r1)
rhs = (sqrt (2 * r2 / (r1 + r2))) - 1
-- same note as above
delta2 :: Double -> Double -> Vector -> Vector
delta2 r1 r2 vec = (lhs*rhs) `times` vec
where
lhs = sqrt (mu / r2)
rhs = 1 - (sqrt (2 * r1 / (r1 + r2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment