Function Repository Resource:

CompassPoint

Source Notebook

Returns a string with the closest (inter)cardinal direction

Contributed by: Sander Huisman

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.

Details

Bearings go from 0° being North and goes clockwise such that 90° corresponds to East, 180° to South and 270° to West.
b can be specified in the form Quantity[b,"Degrees"].

Examples

Basic Examples (1) 

Create a string representation of an 51° bearing on an 8 point wind rose:

In[1]:=
ResourceFunction["CompassPoint"][51]
Out[1]=

Scope (3) 

Use a 32-point wind rose:

In[2]:=
ResourceFunction["CompassPoint"][74, 32]
Out[2]=

Use a degree Quantity instead:

In[3]:=
ResourceFunction["CompassPoint"][Quantity[74, "Degrees"], 32]
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]
Out[4]=

Possible Issues (1) 

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}
Out[5]=

Neat Examples (1) 

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
 ]
Out[6]=

Publisher

SHuisman

Version History

  • 1.0.1 – 26 April 2021

License Information