Equation of a normal to a Circle from a given point | Java program for the above approach ; Function to calculate the slope ; Store the coordinates the center of the circle ; If slope becomes infinity ; Stores the slope ; If slope is zero ; Return the result ; Function to find the equation of the normal to a circle from a given point ; Stores the slope of the normal ; If slope becomes infinity ; If slope is zero ; Otherwise , print the equation of the normal ; Driver Code ; Given Input ; Function Call
import java . util . * ; class GFG { static double normal_slope ( double a , double b , double x1 , double y1 ) { double g = a / 2 ; double f = b / 2 ; if ( g - x1 == 0 ) return ( - 1 ) ; double slope = ( f - y1 ) / ( g - x1 ) ; if ( slope == 0 ) return ( - 2 ) ; return slope ; } static void normal_equation ( double a , double b , double x1 , double y1 ) { double slope = normal_slope ( a , b , x1 , y1 ) ; if ( slope == - 1 ) { System . out . print ( " x ▁ = ▁ " + x1 ) ; } if ( slope == - 2 ) { System . out . print ( " y ▁ = ▁ " + y1 ) ; } if ( slope != - 1 && slope != - 2 ) { x1 *= - slope ; x1 += y1 ; if ( x1 > 0 ) System . out . print ( " y ▁ = ▁ " + slope + " x ▁ + ▁ " + x1 ) ; else System . out . print ( " y ▁ = ▁ " + slope + " x ▁ " + x1 ) ; } } public static void main ( String [ ] args ) { int a = 4 , b = 6 ; int x1 = 12 , y1 = 14 ; normal_equation ( a , b , x1 , y1 ) ; } }