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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:28:18+00:00 2026-06-07T01:28:18+00:00

I am attempting to write a function that will tell me if an angle

  • 0

I am attempting to write a function that will tell me if an angle lies within 2 other angles. When say ‘if an angle lies within 2 other angles’ I mean for example, if I have the 2 angles 0 and 90 then 45 would lie between those angles but -20(or 99) would not.

My Problem: My function doesn’t seem to be detecting when 2 angles lie within 2 angles when it should. I’m not sure if my function works for negative angles aswell?

What do I need to change to get my function working correctly?

bool is_angle_between(int target, int angle1, int angle2)
{
  // Post: Return true if target lies between the 2 angles

  int iTarget = (360 + (target % 360)) % 360;
  int iAngle1 = (3600000 + angle1) % 360;
  int iAngle2 = (3600000 + angle2) % 360;

  if (iAngle1 < iAngle2)
    if (iAngle1 <= iTarget && iTarget <= iAngle2)
      return true;
  else if (iAngle1 <= iTarget || iTarget <= iAngle2)
    return true;

  return false;
}
  • 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-07T01:28:20+00:00Added an answer on June 7, 2026 at 1:28 am

    Seems like this should work:

    if (iAngle1 < iAngle2) {
        if (iAngle1 <= iTarget && iTarget <= iAngle2) {
            return true;
        }
    }
    else {
        if (iAngle2 <= iTarget && iTarget <= iAngle1) {
            return true;
        }
    }
    
    return false;
    

    Note that the braces here help ensure that the else matches the if you intend it to. Your original code is indented as you want it to match, but that isn’t how it’s parsed.

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

Sidebar

Related Questions

I have been attempting to write a VBA Script that can parse out other
Is this possible? I am attempting to write a function for onmousedown that will
I'm looking to write a jQuery function that will change the value of other
I'm attempting to write a function in assembly that will detect if a longer
I am attempting to write a JS function (using prototype in rails) that will
I am attempting to write a interpreter that will turn a string like: vector(random(0,
I am attempting to write some jQuery code that will expand a paragraph when
R version 2.12, Windows XP I am attempting to write a function (say 'g')
I am attempting to write a function which will operate on a std::map of
I'm attempting to write a menu driven modular perl script that will capture user

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.