Equation of a normal to a Circle from a given point | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; 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 ; } void normal_equation ( double a , double b , double x1 , double y1 ) { double slope = normal_slope ( a , b , x1 , y1 ) ; if ( slope == -1 ) { cout << " x ▁ = ▁ " << x1 ; } if ( slope == -2 ) { cout << " y ▁ = ▁ " << y1 ; } if ( slope != -1 && slope != -2 ) { x1 *= - slope ; x1 += y1 ; if ( x1 > 0 ) cout << " y ▁ = ▁ " << slope << " x ▁ + ▁ " << x1 ; else cout << " y ▁ = ▁ " << slope << " x ▁ " << x1 ; } } int main ( ) { int a = 4 , b = 6 , c = 5 ; int x1 = 12 , y1 = 14 ; normal_equation ( a , b , x1 , y1 ) ; return 0 ; }