Find the angle between tangents drawn from a given external point to a Circle | java program for the above approach ; Function to find the distance between center and the exterior point ; Find the difference between the x and y coordinates ; Using the distance formula ; Function to find the angle between the pair of tangents drawn from the point ( X2 , Y2 ) to the circle . ; Calculate the distance between the center and exterior point ; Invalid Case ; Find the angle using the formula ; Print the resultant angle ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static double point_distance ( int x1 , int y1 , int x2 , int y2 ) { int p = ( x2 - x1 ) ; int q = ( y2 - y1 ) ; double distance = Math . sqrt ( p * p + q * q ) ; return distance ; } static void tangentAngle ( int x1 , int y1 , int x2 , int y2 , double radius ) { double distance = point_distance ( x1 , y1 , x2 , y2 ) ; if ( radius / distance > 1 radius / distance < - 1 ) { System . out . println ( - 1 ) ; } double result = 2 * Math . asin ( radius / distance ) * 180 / 3.1415 ; System . out . println ( String . format ( " % .4f " , result ) + " ▁ degrees " ) ; } public static void main ( String [ ] args ) { int radius = 4 ; int x1 = 7 , y1 = 12 ; int x2 = 3 , y2 = 4 ; tangentAngle ( x1 , y1 , x2 , y2 , radius ) ; } }