Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:15:27+00:00 2026-05-25T18:15:27+00:00

I have wind direction data coming from a weather vane, and the data is

  • 0

I have wind direction data coming from a weather vane, and the data is represented in 0 to 359 degrees.

I want to convert this into text format (compass rose) with 16 different directions.

Basically I want to know if there is a fast slick way to scale the angle reading to a 16 string array to print out the correct wind direction without using a bunch of if statements and checking for ranges of angles

Wind direction can be found here.

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:15:27+00:00Added an answer on May 25, 2026 at 6:15 pm

    EDIT :

    Since there is an angle change at every 22.5 degrees, the direction should swap hands after 11.25 degrees.

    Therefore:

    349-360//0-11 = N
    12-33 = NNE
    34-56 = NE
    

    Using values from 327-348 (The entire NNW spectrum) failed to produce a result for eudoxos’ answer.
    After giving it some thought I could not find the flaw in his logic, so i rewrote my own..

    def degToCompass(num):
        val=int((num/22.5)+.5)
        arr=["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
        print arr[(val % 16)]
    
    >>> degToCompass(0)
    N
    >>> degToCompass(180)
    S
    >>> degToCompass(720)
    N
    >>> degToCompass(11)
    N
    >>> 12
    12
    >>> degToCompass(12)
    NNE
    >>> degToCompass(33)
    NNE
    >>> degToCompass(34)
    NE
    

    STEPS :

    1. Divide the angle by 22.5 because 360deg/16 directions = 22.5deg/direction change.
    2. Add .5 so that when you truncate the value you can break the ‘tie’ between the change threshold.
    3. Truncate the value using integer division (so there is no rounding).
    4. Directly index into the array and print the value (mod 16).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plot like this: https://i.stack.imgur.com/zdike.png I need the data coordinates of points
I have this message: image pyimage2 doesn't exist . I want to have multi
I have a graph of wind speeds against direction which has a huge numeber
I have developed a system in R for graphing large datasets obtained from wind
I have a data frame with 3 variables, which are all wind speeds. I
Averaging scalar wind direction data yields inaccurate values due to the compass headings ranging
I have a data model like this in SQL Server: table Note - varchar
I have two arrays that I would like to compare and ultimately wind up
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have an app, backed by Core Data, that I've been working on for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.