Angle difference between two bearings: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Switched to functions over tuples.) |
|||
Line 1,248: | Line 1,248: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang Haskell>import |
<lang Haskell>import Control.Monad (join) |
||
import Data.Bifunctor (bimap) |
|||
import Text.Printf (printf) |
|||
type Radians = Float |
type Radians = Float |
||
Line 1,254: | Line 1,256: | ||
type Degrees = Float |
type Degrees = Float |
||
---------- ANGLE DIFFERENCE BETWEEN TWO BEARINGS --------- |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
= |
|||
⚫ | |||
where |
where |
||
(ax, ay) = (sin a, cos a) |
(ax, ay) = (sin a, cos a) |
||
Line 1,267: | Line 1,272: | ||
| otherwise = -1 |
| otherwise = -1 |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
putStrLn . unlines $ |
putStrLn . unlines $ |
||
fmap |
fmap |
||
(uncurry |
( uncurry (printf "%6.2f° + %6.2f° -> %7.2f°") |
||
<*> angleBetweenDegrees |
|||
) |
|||
[ (20.0, 45.0), |
|||
(-45.0, 45.0), |
|||
(-85.0, 90.0), |
|||
(-95.0, 90.0), |
|||
(-45.0, 125.0), |
|||
(-45.0, 145.0) |
|||
]</lang> |
|||
] |
|||
------------------------- GENERIC ------------------------ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{{Out}} |
{{Out}} |
||
<pre> 20.00° + 45.00° -> 25.00° |
<pre> 20.00° + 45.00° -> 25.00° |