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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:42:52+00:00 2026-06-14T18:42:52+00:00

I am trying to solve simple task, but I am not finding any elegant

  • 0

I am trying to solve simple task, but I am not finding any elegant solution.

I basically solving intersection of two circular sectors.
Each sector is given by 2 angles (from atan2 func) within (-pi, pi] range.
Each selector occupy maximum angle of 179.999. So it can be tell for every two angles where the circular sector is.

The return value should describe mutual intersection based on following:

value <1 if one angle is contained by second one (value represents how much space occupy percentually)

value >1 if first angle (the dotted one) is outside the other one, value represents how much of dotted angle is out of the other one

basic cases and some examples are on image bellow

enter image description here

the problem is that there are so many cases which should be handled and I am looking for some elegant way to solve it.

I can compare two angles only when they are on the right side of unit circle (cos>0) because on the left side, angle numerically bigger is graphically lower. I tried use some projection on the right half:

if(x not in <-pi/2, pi/2>)
{
    c = getSign(x)*pi/2;
    x = c - (x - c);
}

but there is a problem with sectors which occupy part of both halves of unit circle…

There are so many cases… Does somebody know how to solve this elegantly?
(I use c++, but any hint or pseudocode is fine)

  • 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-14T18:42:53+00:00Added an answer on June 14, 2026 at 6:42 pm

    You can do the following:

    1. normalize each sector to the form (s_start, s_end) where s_start is in (-pi,pi] and s_end in [s_start,s_start+pi).
    2. sort (swap) the sectors such that s0_start < s1_start
    3. now we have only 3 cases (a, b1, b2):

      a) s1_start <= s0_end: intersection, s1_start inside s0

      b) s1_start > s0_end:

      b1) s0_start + 2*pi <= s1_end: intersection, (s0_start + 2*pi) inside s1

      b2) s0_start + 2*pi > s1_end: no intersection

    Thus we get the following code:

    const double PI = 2.*acos(0.);
    struct TSector { double a0, a1; };
    
    // normalized range for angle
    bool isNormalized(double a)
    { return -PI < a && a <= PI; }
    // special normal form for sector
    bool isNormalized(TSector const& s)
    { return isNormalized(s.a0) && s.a0 <= s.a1 && s.a1 < s.a0+PI; }
    
    // normalize a sector to the special form:
    // * -PI < a0 <= PI
    // * a0 < a1 < a0+PI
    void normalize(TSector& s)
    {
       assert(isNormalized(s.a0) && isNormalized(s.a1));
    
       // choose a representation of s.a1 s.t. s.a0 < s.a1 < s.a0+2*PI
       double a1_bigger = (s.a0 <= s.a1) ? s.a1 : s.a1+2*PI;
       if (a1_bigger >= s.a0+PI)
         std::swap(s.a0, s.a1);
       if (s.a1 < s.a0)
         s.a1 += 2*PI;
    
       assert(isNormalized(s));
    }
    
    bool intersectionNormalized(TSector const& s0, TSector const& s1,
                                TSector& intersection)
    {
      assert(isNormalized(s0) && isNormalized(s1) && s0.a0 <= s1.a0);
    
      bool isIntersecting = false;
      if (s1.a0 <= s0.a1) // s1.a0 inside s0 ?
      {
        isIntersecting = true;
        intersection.a0 = s1.a0;
        intersection.a1 = std::min(s0.a1, s1.a1);
      }
      else if (s0.a0+2*PI <= s1.a1) // (s0.a0+2*PI) inside s1 ?
      {
        isIntersecting = true;
        intersection.a0 = s0.a0;
        intersection.a1 = std::min(s0.a1, s1.a1-2*PI);
      }
      assert(!isIntersecting || isNormalized(intersection));
    
      return isIntersecting;
    }
    
    main()
    {
      TSector s0, s1;
      s0.a0 = ...
      normalize(s0);
      normalize(s1);
      if (s1.a0 < s0.a0)
        std::swap(s0, s1);
      TSection intersection;
      bool isIntersection = intersectionNormalized(s0, s1, intersection);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to solve a very simple problem using mvvm-light, but after days of sifting
i'm trying to solve a seemingly simple problem, but just can't quite get my
I know this is simple but my brain is fried from trying to solve
Good evening, people! I'm trying to solve a rather simple problem, but.. well, it
Hi all! I'm trying to solve an -apparently- simple problem, but I cannot fix
I'm trying to solve a really simple problem of finding object position under force
I'm trying to solve tic-tac-toe with a simple minimax algorithm. Simple, but should cover
So I'm trying to figure out the best way to solve simple logarithms using
Problem Solved - See bottom for solution notes I'm trying to build a simple
Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names):

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.