It is currently March 28th, 2024, 7:18 pm

Convert Degrees to Cardinal Direction

Tips and Tricks from the Rainmeter Community
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Convert Degrees to Cardinal Direction

Post by Kaelri »

This measure will convert a heading value (in degrees) to the corresponding cardinal direction, with a resolution of 32 subdivisions, as per here. The actual formula returns an integer (1-32), and the substitute assigns a string value to each.

Remember that navigational angles start from 12 o'clock and go clockwise, unlike geometric angles, which start from 3 o'clock and go counterclockwise.

Code: Select all

[MeasureCardinal]
Measure=Calc
Formula=FLOOR(((MeasureDegrees/11.25)+1.5) < 33 ? ((MeasureDegrees/11.25)+1.5) : ((MeasureDegrees/11.25)+1.5)-32)
Substitute="10":"EbS","11":"ESE","12":"SEbE","13":"SE","14":"SEbS","15":"SSE","16":"SbE","17":"S","18":"SbW","19":"SSW","20":"SWbS","21":"SW","22":"SWbW","23":"WSW","24":"WbSW","25":"W","26":"WbN","27":"WNW","28":"NWbW","29":"NW","30":"NWbN","31":"NNW","32":"NbW","1":"N","2":"NbE","3":"NNE","4":"NEbN","5":"NE","6":"NEbE","7":"ENE","8":"EbN","9":"E"