Java Program to Check Whether a Point Exists in Circle Sector or Not

bookmark

class Main

    //main method
    public static void main(String arg[]) 
    { 
        int radius = 8;
        int x = 3;
        int y = 4; 
        float startAngle = 0; 
        float percent = 12;
        //calling the checkPoint() method
        checkPoint(radius, x, y, percent, startAngle); 
    }
    
    //user defined method
    static void checkPoint(int radius, int x, int y, float percent, float startAngle) 
    { 
      
        //find endAngle 
        float endAngle = 360/percent + startAngle; 
       
        //find polar co-ordinates 
        double polarRadius = Math.sqrt(x*x+y*y); 
        double Angle = Math.atan(y/x); 
       
        // Checking whether polarradius is less then radius of circle or not 
        // and checking whether Angle is between startAngle and endAngle or not 
        if (Angle>=startAngle && Angle<=endAngle && polarRadius<rad) 
        
            System.out.print("Point"+"("+x+","+y+")"+ 
            " exist in the circle sector"); 
        else
        
            System.out.print("Point"+"("+x+","+y+")"+ 
            " exist in the circle sector"); 
    } 
}

 


Output:

Point(3,4) exist in the circle sector