Angle difference between two bearings: Difference between revisions
Content added Content deleted
m (→JS ES6: Layout, function name) |
m (→{{header|Haskell}}: (layout, function name, narrowed import)) |
||
Line 185: | Line 185: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
⚫ | |||
⚫ | |||
type Radians = Float |
type Radians = Float |
||
Line 193: | Line 192: | ||
angleBetweenDegrees :: Degrees -> Degrees -> Degrees |
angleBetweenDegrees :: Degrees -> Degrees -> Degrees |
||
angleBetweenDegrees a b = degrees $ |
angleBetweenDegrees a b = degrees $ bearingDelta (radians a) (radians b) |
||
bearingDelta :: Radians -> Radians -> Radians |
|||
bearingDelta a b -- sign * dot-product |
|||
= sign * acos ((ax * bx) + (ay * by)) |
= sign * acos ((ax * bx) + (ay * by)) |
||
where |
where |
||
Line 213: | Line 212: | ||
radians = (/ 180) . (pi *) |
radians = (/ 180) . (pi *) |
||
-- TEST ----------------------------------------------------------------------- |
|||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
Line 227: | Line 227: | ||
displayRow (x, y) = |
displayRow (x, y) = |
||
printf "%6.2f° + %6.2f° -> %7.2f°" x y $ angleBetweenDegrees x y</lang> |
printf "%6.2f° + %6.2f° -> %7.2f°" x y $ angleBetweenDegrees x y</lang> |
||
{{Out}} |
{{Out}} |
||
<pre> 20.00° + 45.00° -> 25.00° |
<pre> 20.00° + 45.00° -> 25.00° |