Dados tres enteros a, b, c que representan coeficientes de la ecuación x 2 + y 2 + ax + by + c = 0 de un círculo , la tarea es encontrar la ecuación de la normal al círculo desde un punto dado (x 1 , y 1 ) .
Nota: Normal es una línea perpendicular a la tangente en el punto de contacto entre la tangente y la curva.
Ejemplos:
Entrada: a = 4, b = 6, c = 5, x 1 = 12, y 1 = 14
Salida: y = 1,1x + 0,8Entrada: a = 6, b = 12, c = 5, x 1 = 9, y 1 = 3
Salida: y = -0,5x + 7,5
Enfoque: siga los pasos a continuación para resolver el problema:
- La normal a una circunferencia pasa por el centro de la circunferencia.
- Por lo tanto, encuentre las coordenadas del centro del círculo (g, f) , donde g = a/2 y f = b/2 .
- Dado que el centro del círculo y el punto donde se dibuja la normal se encuentran en la normal, calcule la pendiente de la normal (m) como m = (y 1 – f) / (x 1 – g) .
- Por lo tanto, la ecuación de la normal es y – y 1 = m * (x – x 1 ) .
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program for the above approach #include <bits/stdc++.h> using namespace std; // Function to calculate the slope double normal_slope(double a, double b, double x1, double y1) { // Store the coordinates // the center of the circle double g = a / 2; double f = b / 2; // If slope becomes infinity if (g - x1 == 0) return (-1); // Stores the slope double slope = (f - y1) / (g - x1); // If slope is zero if (slope == 0) return (-2); // Return the result return slope; } // Function to find the equation of the // normal to a circle from a given point void normal_equation(double a, double b, double x1, double y1) { // Stores the slope of the normal double slope = normal_slope(a, b, x1, y1); // If slope becomes infinity if (slope == -1) { cout << "x = " << x1; } // If slope is zero if (slope == -2) { cout << "y = " << y1; } // Otherwise, print the // equation of the normal if (slope != -1 && slope != -2) { x1 *= -slope; x1 += y1; if (x1 > 0) cout << "y = " << slope << "x + " << x1; else cout << "y = " << slope << "x " << x1; } } // Driver Code int main() { // Given Input int a = 4, b = 6, c = 5; int x1 = 12, y1 = 14; // Function Call normal_equation(a, b, x1, y1); return 0; }
Java
// Java program for the above approach import java.util.*; class GFG{ // Function to calculate the slope static double normal_slope(double a, double b, double x1, double y1) { // Store the coordinates // the center of the circle double g = a / 2; double f = b / 2; // If slope becomes infinity if (g - x1 == 0) return (-1); // Stores the slope double slope = (f - y1) / (g - x1); // If slope is zero if (slope == 0) return (-2); // Return the result return slope; } // Function to find the equation of the // normal to a circle from a given point static void normal_equation(double a, double b, double x1, double y1) { // Stores the slope of the normal double slope = normal_slope(a, b, x1, y1); // If slope becomes infinity if (slope == -1) { System.out.print("x = " + x1); } // If slope is zero if (slope == -2) { System.out.print("y = " + y1); } // Otherwise, print the // equation of the normal 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); } } // Driver Code public static void main(String[] args) { // Given Input int a = 4, b = 6; int x1 = 12, y1 = 14; // Function Call normal_equation(a, b, x1, y1); } } // This code is contributed by 29AjayKumar
Python3
# Python3 program for the above approach # Function to calculate the slope def normal_slope(a, b, x1, y1): # Store the coordinates # the center of the circle g = a / 2 f = b / 2 # If slope becomes infinity if (g - x1 == 0): return (-1) # Stores the slope slope = (f - y1) / (g - x1) # If slope is zero if (slope == 0): return (-2) # Return the result return slope # Function to find the equation of the # normal to a circle from a given point def normal_equation(a, b, x1, y1): # Stores the slope of the normal slope = normal_slope(a, b, x1, y1) # If slope becomes infinity if (slope == -1) : print("x = ", x1) # If slope is zero if (slope == -2) : print("y = ", y1) # Otherwise, print the # equation of the normal if (slope != -1 and slope != -2): x1 *= -slope x1 += y1 if (x1 > 0) : print("y = ", slope, "x + ", x1) else : print("y = ", slope, "x ", x1) # Driver Code # Given Input a = 4 b = 6 c = 5 x1 = 12 y1 = 14 # Function Call normal_equation(a, b, x1, y1) # This code is contributed by Dharanendra L V.
C#
// C# program for the above approach using System; class GFG{ // Function to calculate the slope static double normal_slope(double a, double b, double x1, double y1) { // Store the coordinates // the center of the circle double g = a / 2; double f = b / 2; // If slope becomes infinity if (g - x1 == 0) return (-1); // Stores the slope double slope = (f - y1) / (g - x1); // If slope is zero if (slope == 0) return (-2); // Return the result return slope; } // Function to find the equation of the // normal to a circle from a given point static void normal_equation(double a, double b, double x1, double y1) { // Stores the slope of the normal double slope = normal_slope(a, b, x1, y1); // If slope becomes infinity if (slope == -1) { Console.WriteLine( "x = " + x1); } // If slope is zero if (slope == -2) { Console.WriteLine("y = " + y1); } // Otherwise, print the // equation of the normal if (slope != -1 && slope != -2) { x1 *= -slope; x1 += y1; if (x1 > 0) Console.WriteLine("y = " + slope + "x +" + Math.Round(x1, 2)); else Console.WriteLine("y = " + slope + "x " + Math.Round(x1, 2)); } } // Driver code public static void Main(String []args) { // Given Input int a = 4, b = 6; //int c = 5; int x1 = 12, y1 = 14; // Function Call normal_equation(a, b, x1, y1); } } // This code is contributed by sanjoy_62
Javascript
<script> // JavaScript program for the above approach // Function to calculate the slope function normal_slope( a, b, x1, y1) { // Store the coordinates // the center of the circle var g = a / 2; var f = b / 2; // If slope becomes infinity if (g - x1 == 0) return (-1); // Stores the slope var slope = (f - y1) / (g - x1); // If slope is zero if (slope == 0) return (-2); // Return the result return slope; } // Function to find the equation of the // normal to a circle from a given point function normal_equation( a, b, x1, y1) { // Stores the slope of the normal var slope = normal_slope(a, b, x1, y1); // If slope becomes infinity if (slope == -1) { document.write("x = " + x1); } // If slope is zero if (slope == -2) { document.write("y = " + y1); } // Otherwise, print the // equation of the normal if (slope != -1 && slope != -2) { x1 *= -slope; x1 += y1; if (x1 > 0) document.write( "y = " + slope + "x + " + x1.toFixed(1) ); else document.write( "y = " + slope+ "x " + x1.toFixed(1) ); } } // Driver Code // Given Input var a = 4, b = 6, c = 5; var x1 = 12, y1 = 14; // Function Call normal_equation(a, b, x1, y1); </script>
y = 1.1x + 0.8
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por arjundevmishra6 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA