Jump to content

Angle difference between two bearings: Difference between revisions

m
→‎{{header|Haskell}}: (layout, function name, narrowed import)
m (→‎JS ES6: Layout, function name)
m (→‎{{header|Haskell}}: (layout, function name, narrowed import))
Line 185:
 
=={{header|Haskell}}==
<lang Haskell>import Text.Printf (printf)
 
<lang Haskell>import Text.Printf
 
type Radians = Float
Line 193 ⟶ 192:
 
angleBetweenDegrees :: Degrees -> Degrees -> Degrees
angleBetweenDegrees a b = degrees $ relBearingbearingDelta (radians a) (radians b)
 
relBearingbearingDelta :: Radians -> Radians -> Radians
relBearingbearingDelta a b -- sign * dot-product
= sign * acos ((ax * bx) + (ay * by))
where
Line 213 ⟶ 212:
radians = (/ 180) . (pi *)
 
-- TEST -----------------------------------------------------------------------
main :: IO ()
main =
Line 227:
displayRow (x, y) =
printf "%6.2f° + %6.2f° -> %7.2f°" x y $ angleBetweenDegrees x y</lang>
 
{{Out}}
<pre> 20.00° + 45.00° -> 25.00°
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.