Check whether a point exists in circle sector or not.


We have a circle centered at origin (0, 0). As input we are given with starting angle of the circle sector and the size of the circle sector in percentage.

Input :  Radius = 8 
         StartAngle = 0 
         Percentage = 12 
         x = 3 y = 4 
Output : Point (3, 4) exists in the circle 

Input : Radius = 12 
        Startangle = 45
        Percentage = 25  
        x = 3 y = 4 
Output : Point (3, 4) does not exist in 
         the circle sector

In this image starting angle is 0 degree, radius r and suppose that percentage of colored area is 12% then we calculate Ending Angle as 360/percentage + starting angle.

To find whether a point (x, y) exists in a circle sector (centered at origin) or not we find polar coordinates of that point and then go through the following steps:

  1. Convert x, y to polar coordinates using this
    Angle = atan(y/x); Radius = sqrt(x * x + y * y);
  2. Then Angle must be between StartingAngle and EndingAngle, and Radius between 0 and your Radius.
// C++ program to check if a point lies inside a circle
// sector.
using namespace std;

void checkPoint(int radius, int x, int y, float percent,
                                         float startAngle)
    // calculate endAngle
    float endAngle = 360/percent + startAngle;

    // Calculate polar co-ordinates
    float polarradius = sqrt(x*x+y*y);
    float Angle = atan(y/x);

    // Check whether polarradius is less then radius of circle
    // or not and Angle is between startAngle and endAngle
    // or not
    if (Angle>=startAngle && Angle<=endAngle && polarradius<radius)
        printf("Point (%d, %d) exist in the circle sector\n", x, y);
        printf("Point (%d, %d) does not exist in the circle sector\n",
                                                              x, y);

// Driver code
int main()
    int radius = 8, x = 3, y = 4;
    float percent  = 12, startAngle = 0;
    checkPoint(radius, x, y, percent, startAngle);
    return 0;

Output: Point(3, 4) exists in the circle sector

Time complexity = O(1)

This article is contributed by Niteesh kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

GATE CS Corner    Company Wise Coding Practice

Please write to us at to report any issue with the above content.

Recommended Posts:

2.6 Average Difficulty : 2.6/5.0
Based on 6 vote(s)

Writing code in comment? Please use, generate link and share the link here.