Created
November 3, 2012 15:47
-
-
Save laszlokorte/4007699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define (degree->cardinal degree) | |
(case (modulo (inexact->exact (round (* 32 (/ degree 360)))) 32) | |
((0) "N") | |
((1) "NbE") | |
((2) "NNE") | |
((3) "NEbN") | |
((4) "NE") | |
((5) "NEbE") | |
((6) "ENE") | |
((7) "EbN") | |
((8) "E") | |
((9) "EbS") | |
((10) "ESE") | |
((11) "SEbE") | |
((12) "SE") | |
((13) "SEbS") | |
((14) "SSE") | |
((15) "SbE") | |
((16) "S") | |
((17) "SbW") | |
((18) "SSW") | |
((19) "SWbS") | |
((20) "SW") | |
((21) "SWbW") | |
((22) "WSW") | |
((23) "WbS") | |
((24) "W") | |
((25) "WbN") | |
((26) "WNW") | |
((27) "NWbW") | |
((28) "NW") | |
((29) "NWbN") | |
((30) "NNW") | |
((31) "NbW") | |
(else "unknwown"))) | |
(define (cardinal->degree card) | |
(/ (* 360 (case card | |
(("N") 0) | |
(("NbE") 1) | |
(("NNE") 2) | |
(("NEbN") 3) | |
(("NE") 4) | |
(("NEbE") 5) | |
(("ENE") 6) | |
(("EbN") 7) | |
(("E") 8) | |
(("EbS") 9) | |
(("ESE") 10) | |
(("SEbE") 11) | |
(("SE") 12) | |
(("SEbS") 13) | |
(("SSE") 14) | |
(("SbE") 15) | |
(("S") 16) | |
(("SbW") 17) | |
(("SSW") 18) | |
(("SWbS") 19) | |
(("SW") 20) | |
(("SWbW") 21) | |
(("WSW") 22) | |
(("WbS") 23) | |
(("W") 24) | |
(("WbN") 25) | |
(("WNW") 26) | |
(("NWbW") 27) | |
(("NW") 28) | |
(("NWbN") 29) | |
(("NNW") 30) | |
(("NbW") 31) | |
(else -1))) 32)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment