Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Returns a string with the closest (inter)cardinal direction
| ResourceFunction["CompassPoint"][b] returns a string for the bearing b from an 8-wind compass rose. | |
| ResourceFunction["CompassPoint"][b,n] returns a string for the bearing b from an n-wind compass rose, where n= 4, 8, 16 or 32. | 
Create a string representation of an 51° bearing on an 8 point wind rose:
| In[1]:= | ![ResourceFunction["CompassPoint"][51]](https://www.wolframcloud.com/obj/resourcesystem/images/fb9/fb9ec21b-0d4f-449c-8e2f-3c7c9163b288/4cab61eb24d31b73.png) | 
| Out[1]= |  | 
Use a 32-point wind rose:
| In[2]:= | ![ResourceFunction["CompassPoint"][74, 32]](https://www.wolframcloud.com/obj/resourcesystem/images/fb9/fb9ec21b-0d4f-449c-8e2f-3c7c9163b288/461690be3b9ed12c.png) | 
| Out[2]= |  | 
Use a degree Quantity instead:
| In[3]:= | ![ResourceFunction["CompassPoint"][Quantity[74, "Degrees"], 32]](https://www.wolframcloud.com/obj/resourcesystem/images/fb9/fb9ec21b-0d4f-449c-8e2f-3c7c9163b288/5e0db8768e7ef360.png) | 
| Out[3]= |  | 
Negative angles are allowed and equivalent to their positive angle by adding 360°:
| In[4]:= | ![ResourceFunction["CompassPoint"][-7, 32] === ResourceFunction["CompassPoint"][353, 32]](https://www.wolframcloud.com/obj/resourcesystem/images/fb9/fb9ec21b-0d4f-449c-8e2f-3c7c9163b288/24388a319cfbfa60.png) | 
| Out[4]= |  | 
Each sector has two borders, the border in the clockwise direction belong to the sector, the other border to the previous section:
| In[5]:= | ![ResourceFunction["CompassPoint"][#, 4] & /@ {-45, 0, 45}](https://www.wolframcloud.com/obj/resourcesystem/images/fb9/fb9ec21b-0d4f-449c-8e2f-3c7c9163b288/0c4b99f965e7b9d3.png) | 
| Out[5]= |  | 
Make a compass:
| In[6]:= | ![Graphics[{
  Text[ResourceFunction["CompassPoint"][90 - #, 32], AngleVector[N[#] Degree], {0, 0}, If[#[[1]] < 0, -#, #] &[AngleVector[N[#] Degree]]] & /@ Most@Range[0, 360, 360/32],
  Text[ToString[#] <> "\[Degree]", 1.12 AngleVector[Pi/2 - N[#] Degree], {0, 0}, If[#[[1]] < 0, -#, #] &[AngleVector[Pi/2 - N[#] Degree]]] & /@ Most@Range[0, 360, 5],
  Thickness[0.01], Arrowheads[0.1], Arrow[{{0, 0}, AngleVector[{0.9, Degree #}]}] & /@ Range[0, 270, 90],
  Thickness[0.01 2/3], Arrowheads[0.1 2/3], Arrow[{{0, 0}, AngleVector[{0.75, Degree #}]}] & /@ Range[45, 315, 90],
  Thickness[0.01 1/3], Arrowheads[0.1 1/3], Arrow[{{0, 0}, AngleVector[{0.6, Degree #}]}] & /@ Range[22.5, 360, 45],
  Thickness[0.01 1/6], Arrowheads[0.1 1/6], Arrow[{{0, 0}, AngleVector[{0.45, Degree #}]}] & /@ Range[11.25, 360, 22.5]
  },
 PlotRange -> 1.25,
 ImageSize -> 600
 ]](https://www.wolframcloud.com/obj/resourcesystem/images/fb9/fb9ec21b-0d4f-449c-8e2f-3c7c9163b288/6d96c4145c486183.png) | 
| Out[6]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License