The Wayback Machine - https://web.archive.org/web/20240928070511/https://www.geeksforgeeks.org/check-whether-point-exists-circle-sector-not/
Open In App

Check whether a point exists in circle sector or not.

Last Updated : 22 Jun, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. 

Examples: 

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

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

 

Source:wikibooks.org

Source:wikibooks.org

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++




// C++ program to check if a point lies inside a circle
// sector.
#include<bits/stdc++.h>
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);
    else
        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;
}


Java




// Java program to check if
// a point lies inside a circle
// sector.
 
class GFG
{
static void checkPoint(int radius, int x, int y, float percent,
                                         float startAngle)
{
 
    // calculate endAngle
    float endAngle = 360/percent + startAngle;
  
    // Calculate polar co-ordinates
    double polarradius = Math.sqrt(x*x+y*y);
    double Angle = Math.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)
        System.out.print("Point"+"("+x+","+y+")"+
        " exist in the circle sector\n");
    else
        System.out.print("Point"+"("+x+","+y+")"+
        " exist in the circle sector\n");
}
 
// Driver Program to test above function
public static void main(String arg[])
{
    int radius = 8, x = 3, y = 4;
    float percent  = 12, startAngle = 0;
    checkPoint(radius, x, y, percent, startAngle);
}
}
 
// This code is contributed
// by Anant Agarwal.


Python3




# Python3 program to check if a point
# lies inside a circle sector.
import math
 
def checkPoint(radius, x, y, percent, startAngle):
 
    # calculate endAngle
    endAngle = 360 / percent + startAngle
 
    # Calculate polar co-ordinates
    polarradius = math.sqrt(x * x + y * y)
    Angle = math.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 and Angle <= endAngle
                        and polarradius < radius):
        print("Point (", x, ",", y, ") "
              "exist in the circle sector")
    else:
        print("Point (", x, ",", y, ") "
              "does not exist in the circle sector")
 
# Driver code
radius, x, y = 8, 3, 4
percent, startAngle = 12, 0
 
checkPoint(radius, x, y, percent, startAngle)
 
# This code is contributed by
# Smitha Dinesh Semwal


C#




// C# program to check if a point lies
// inside a circle sector.
using System.IO;
using System;
 
class GFG {
     
    static 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 =
                    (float)Math.Sqrt(x * x + y * y);
                     
        float Angle = (float)Math.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)
            Console.Write("Point ({0}, {1}) exist in "
                         + "the circle sector", x, y);
        else
            Console.Write("Point ({0}, {1}) does not "
                + "exist in the circle sector", x, y);
    }
     
    // Driver code
    public static void Main()
    {
        int radius = 8, x = 3, y = 4;
        float percent = 12, startAngle = 0;
        checkPoint(radius, x, y, percent, startAngle);
    }
}
 
// This code is contributed by Smitha Dinesh Semwal


Javascript




<script>
 
// Javascript program to check if
// a point lies inside a circle
// sector.
function checkPoint(radius, x, y, percent, startAngle)
{
     
    // Calculate endAngle
    let endAngle = 360 / percent + startAngle;
    
    // Calculate polar co-ordinates
    let polarradius = Math.sqrt(x * x + y * y);
    let Angle = Math.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)
        document.write("Point" + "(" + x + 
                       "," + y + ")" +
        " exist in the circle sector\n");
    else
        document.write("Point" + "(" + x +
                       "," + y + ")" +
        " exist in the circle sector\n");
}
      
// Driver code   
let radius = 8, x = 3, y = 4;
let percent  = 12, startAngle = 0;
 
checkPoint(radius, x, y, percent, startAngle);
 
// This code is contributed by splevel62
           
</script>


Output : 

Point(3, 4) exists in the circle sector

Time complexity:  O(1)
Auxiliary Space: O(1)

 



Similar Reads

Check if a circle lies inside another circle or not
Given two circles with radii and centres given. The task is to check whether the smaller circle lies inside the bigger circle or not.  Examples:   Input: x1 = 10, y1 = 8, x2 = 1, y2 = 2, r1 = 30, r2 = 10 Output: The smaller circle lies completely inside the bigger circle without touching each other at a point of circumference. Input :x1 = 7, y1 = 8
6 min read
Check if a point having maximum X and Y coordinates exists or not
Given a 2D array arr[] consisting of N coordinates of the form (X, Y), the task is to find a coordinate from the given array such that the X-coordinate of this point is greater than all other X-coordinates and the Y-coordinate of this point is greater than all other Y-coordinates. If no such point exists, print -1. Examples: Input: arr[][] = {(1, 2
13 min read
Check whether the number exists in Arithmetic sequence or not
Given three integers 'A' denotes the first term of an arithmetic sequence, 'C' denotes the common difference between an arithmetic sequence and an integer 'B', the task is to tell whether 'B' exists in the arithmetic sequence or not. Return 1 if B is present in the sequence. Otherwise, returns 0. Examples: Input: A = 1, B = 3, C = 2Output: 1Explana
5 min read
Check whether a point lies inside a sphere or not
Given co-ordinates of the center of a sphere (cx, cy, cz) and its radius r. Our task is to check whether a point (x, y, z) lies inside, outside or on this sphere.Examples: Input : Centre(0, 0, 0) Radius 3 Point(1, 1, 1) Output :Point is inside the sphere Input :Centre(0, 0, 0) Radius 3 Point(2, 1, 2) Output :Point lies on the sphere Input :Centre(0
7 min read
Check whether a given point lies inside a triangle or not
Given three corner points of a triangle, and one more point P. Write a function to check whether P lies within the triangle or not. Example: Input: A = (0, 0), B = (10, 30), C = (20, 0), P(10, 15)Output: InsideExplanation: B(10,30) / \ / \ / \ / P \ P' / \ A(0,0) ----------- C(20,0) Input: A = (0, 0), B = (10, 30), C = (20, 0), P(30, 15)Output: Out
15+ min read
Check whether a given point lies inside a rectangle or not
Given four points of a rectangle, and one more point P. Write a function to check whether P lies within the given rectangle or not.Examples:   Input : R = [(10, 10), (10, -10), (-10, -10), (-10, 10)] P = (0, 0)Output : yesIllustration : Input : R = [(10, 10), (10, -10), (-10, -10), (-10, 10)], P = (20, 20)Output : noIllustration : Prerequisite: Che
14 min read
Check if any point overlaps the given Circle and Rectangle
Given two opposite diagonal points of a rectangle (X1, Y1), (X2, Y2) and the center, radius of the circle R, (Xc, Yc), the task is to check if there exists any point P that belongs to both the circle as well as the rectangle. Examples: Input: R = 2, Xc = 0, Yc = 0, X1 = 1, Y1 = 0, X2 = 3, Y2 = 3 Output: true Explanation: Clearly, from the below ill
7 min read
Check if it is possible to reach any point on the circumference of a given circle from origin
Given a string S representing a sequence of moves(L, R, U, and D) and an integer R representing the radius of a circle whose center is the origin (0, 0), the task is to check if it is possible to reach any point on the circumference of the given circle from the origin by choosing any subsequence of moves from the string S. If it is possible to reac
10 min read
Check if any point exists in a plane whose Manhattan distance is at most K from N given points
Given two arrays A[] and B[] consisting of X and Y coordinates of N distinct points in a plane, and a positive integer K, the task is to check if there exists any point P in the plane such that the Manhattan distance between the point and all the given points is at most K. If there exists any such point P, then print "Yes". Otherwise, print "No". E
7 min read
Check whether it is possible to join two points given on circle such that distance between them is k
Given two circles and a length, K. Find whether we can join two points (one on perimeter of each circle), so that distance between the points is K. (Coordinates of both points need not be an integer value). Examples: Input: Circle-1 Center (0, 0) Radius = 5 Circle-2 Center (8, 3) Radius = 2 K = 3 Output: Yes Maximum Distance: 15 Minimum Distance: 2
10 min read
Check whether given circle resides in boundary maintained by two other circles
Given outer circle radius R and inner circle radius r, making circles from the same center and forming the boundary between them. Now, given X and Y coordinates which denote the center of the new circle to be formed with radius rad, your task is to check whether the circle with coordinates X and Y as the center can fit in the boundary of circles fo
6 min read
Check whether (i,j) exists such that arr[i] != arr[j] and arr[arr[i]] is equal to arr[arr[j]]
Given an array A[]. The task is to determine if it is possible to choose two indices 'i' and 'j' such that the below conditions gets satisfied:- A[i] is not equal to A[j].A[A[i]] is equal to A[A[j]]. Note: The value of the elements in an array is less than the value of N i.e. For every i, arr[i] < N. Examples: Input: N = 4, A[] = {1, 1, 2, 3} Ou
10 min read
Check whether a subsequence exists with sum equal to k if arr[i]> 2*arr[i-1]
Given a sorted array of positive integers where arr[i] > 2*arr[i-1], check whether a sub sequence exists whose sum is equal to k.Examples: Input : arr[]={ 1, 3, 7, 15, 31}, K=18 Output :True A[1] + A[3] = 3 + 15 = 18 We found a subsequence whose sum is 18 Input :arr[]={ 1, 3, 7, 15, 31}, K=20 Output :False No subsequence can be found with sum 20
5 min read
Check whether there exists a triplet (i, j, k) such that arr[i] < arr[k] < arr[j] for i < j < k
Given an array arr[], the task is to check that if there exist a triplet (i, j, k) such that arr[i]<arr[k]<arr[j] and i<j<k then print Yes else print No. Examples: Input: arr[] = {1, 2, 3, 4, 5}Output: NoExplanation:There is no such sub-sequence such that arr[i] < arr[k] < arr[j] Input: arr[] = {3, 1, 5, 0, 4}Output: YesExplanatio
11 min read
Check whether a given point lies on or inside the rectangle | Set 3
Given two numbers a and b where b < a form a rectangle with points (0, b), (b, 0), (a-b, b), (b, a-b). Given a point (x, y), the task is to check whether this point lies inside or on the rectangle or not. Examples: Input: a = 7, b = 2, x = 5, y = 2; Output: Given point does not lie on the rectangle Input: a = 7, b = 2, x = 4, y = 5; Output: Give
6 min read
Check whether the given floating point number is a palindrome
Given a floating-point number N, the task is to check whether it is palindrome or not. Input: N = 123.321 Output: YesInput: N = 122.1 Output: No Approach: First, convert the given floating-point number into a character array.Initialize the low to first index and high to the last index.While low < high: If the character at low is not equal to the
4 min read
Check whether given floating point number is even or odd
Given a floating-point number, check whether it is even or odd. We can check whether a integer is even or odd by dividing its last digit by 2. But in case of floating point number we can't check a given number is even or odd by just dividing its last digit by 2. For example, 100.70 is an odd number but its last digit is divisible by 2. Examples : I
6 min read
Check whether the point (x, y) lies on a given line
Given the values of m and c for the equation of a line y = (m * x) + c, the task is to find whether the point (x, y) lies on the given line. Examples: Input: m = 3, c = 2, x = 1, y = 5 Output: Yes m * x + c = 3 * 1 + 2 = 3 + 2 = 5 which is equal to y Hence, the given point satisfies the line's equation Input: m = 5, c = 2, x = 2, y = 5 Output: No A
4 min read
Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
Given are two congruent circles with two equal chords. The angle subtended to the center from the chord of one of the circles is given. The task is to find the angle subtended by the chord to the center of another circle.Examples: Input: z = 48 Output: 48 degrees Input: z = 93 Output: 93 degrees Approach: In triangle AOB and PXQ AO = PX(radii of co
3 min read
Find area of the larger circle when radius of the smaller circle and difference in the area is given
Given two integers r and d where r is the radius of the smaller circle and d is the difference of the area of this circle with some larger radius circle. The task is to find the area of the larger circle.Examples: Input: r = 4, d = 5 Output: 55.24 Area of the smaller circle = 3.14 * 4 * 4 = 50.24 55.24 - 50.24 = 5Input: r = 12, d = 3 Output: 455.16
4 min read
Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
Given a circle C1 and it's a radius r1. And one another circle C2 whose passes through center of circle C1 and touch the circumference of circle C1. The task is to find out the area of circle C2. Examples: Input: r1 = 4Output:Area of circle c2 = 12.56Input: r1 = 7Output:Area of circle c2 = 38.465 Approach: Radius r2 of circle C2 is [Tex]\ r2 = r1/2
6 min read
Equation of circle when three points on the circle are given
Given three coordinates that lie on a circle, (x1, y1), (x2, y2), and (x3, y3). The task is to find the equation of the circle and then print the centre and the radius of the circle. The equation of circle in general form is x² + y² + 2gx + 2fy + c = 0 and in radius form is (x - h)² + (y -k)² = r², where (h, k) is the centre of the circle and r is
11 min read
Shortest distance between a point and a circle
Given a circle with a given radius has its centre at a particular position in the coordinate plane. In the coordinate plane, another point is given. The task is to find the shortest distance between the point and the circle.Examples: Input: x1 = 4, y1 = 6, x2 = 35, y2 = 42, r = 5 Output: 42.5079 Input: x1 = 0, y1 = 0, x2 = 5, y2 = 12, r = 3 Output:
4 min read
Find the angle between tangents drawn from a given external point to a Circle
Given a positive integer R representing the radius of the circle and the center of the circle (X1, Y1) and another point (X2, Y2) in the cartesian plane, the task is to find the angle between the pair of tangents drawn from the point (X2, Y2) to the circle. Examples: Input: R = 6, (X1, Y1) = (5, 1), (X2, Y2) = (6, 9)Output: 96.1851 Input: R = 4, (X
7 min read
Equation of a normal to a Circle from a given point
Given three integers a, b, c representing coefficients of the equation x2 + y2 + ax + by + c = 0 of a circle, the task is to find the equation of the normal to the circle from a given point (x1, y1).Note: Normal is a line perpendicular to the tangent at the point of contact between the tangent and the curve. Examples: Input: a = 4, b = 6, c = 5, x1
8 min read
Draw a circle without floating point arithmetic
Given a radius of a circle, draw the circle without using floating point arithmetic.Following program uses a simple concept. Let the radius of the circle be r. Consider a square of size (2r+1)*(2r+1) around the circle to be drawn. Now walk through every point inside the square. For every point (x,y), if (x, y) lies inside the circle (or x2+ y2 <
5 min read
Find if a point lies inside a Circle
Given a circle (coordinates of centre and radius) and a point (coordinate), find if the point lies inside or on the circle, or not. Examples : Input: x = 4, y = 4 // Given Point circle_x = 1, circle_y = 1, rad = 6; // Circle Output: Inside Input: x = 3, y = 3 // Given Point circle_x = 0, circle_y = 1, rad = 2; // Circle Output: Outside We strongly
5 min read
Draw a circle without floating point arithmetic
Given a radius of a circle, draw the circle without using floating point arithmetic.The following program uses a simple concept. Let the radius of the circle be r. Consider a square of size (2r+1)*(2r+1) around the circle to be drawn. Now walk through every point inside the square. For every point (x,y), if (x, y) lies inside the circle (or x^2+ y^
6 min read
Find minimum radius such that atleast k point lie inside the circle
Given a positive integer K, a circle center at (0, 0) and coordinates of some points. The task is to find minimum radius of the circle so that at-least k points lie inside the circle. Output the square of the minimum radius. Examples: Input : (1, 1), (-1, -1), (1, -1), k = 3Output : 2We need a circle of radius at least 2to include 3 points.Input :
12 min read
Neighbors of a point on a circle using Bresenham's algorithm
Given a center of a circle and its radius. our task is to find the neighbors of any point on the discrete circle. Examples:  Input : Center = (0, 0), Radius = 3 Point for determining neighbors = (2, 2)Output : Neighbors of given point are : (1, 3), (3, 1)Input : Center = (2, 2) Radius 2 Point of determining neighbors = (0, 2)Output : Neighbors of g
15 min read
Article Tags :
Practice Tags :