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 9010893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:35:02+00:00 2026-06-16T02:35:02+00:00

Firstly, this may sound very trivial, but currently I am creating a function getQuadrant(degree)

  • 0

Firstly, this may sound very trivial, but currently I am creating a function getQuadrant(degree) for returning a quadrant from a given angle.

For instance, if degree is >= 0 and < 90, it will return 1. If degree is >= 90 and < 180, it will return 2. And so forth. This is very trivial. However, to be able to deal with degrees other than 0-360, I simply normalized those numbers to be in 0-360 degree range first, like this:

            while (angle > 360)
                angle = angle - 360;
            end

            while (angle < 0)
                angle = angle + 360;
            end

After that, I calculate. But to be frank, I hate using while statements like this. Are there other mathematical ways that can point out the quadrant of the angle in one go?

EDIT: I see that there are lots of good answers. Allow me to add “which algorithm will be the fastest?“

  • 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-06-16T02:35:03+00:00Added an answer on June 16, 2026 at 2:35 am

    Take advantage of integer arithmetics:

    angle = angle - (angle/360)*360;
    if (angle < 0) angle = angle + 360;
    

    The idea is, since angle/360 is rounded down (floor()), (angle/360) gives you the k you need to do alpha = beta + 360k.

    The second line is normalizing from [-359,-1] back to [1,359] if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, this is going to sound like homework, but it ain't. Just a problem
Firstly , This may look like a duplicate question but trust me I have
I wonder whether someone may be able to help me please. Firstly, this is
Firstly sorry if this is a common question but I couldn't find anything on
UPDATE: Perhaps this wasn't clear from my original post, but I'm mainly interested in
Firstly, I realise that this is a very similar question to this one: Which
I fear I may be displaying my ignorance with this question, but here goes...
This may be an easy question, but if it is one i haven't found
Firstly my maths is limited, so this question may have a simple answer. So,
Firstly, I apologise if this is a dupe - I suspect it may be

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.