Dados a, b y c los coeficientes de X 2 , X y el término constante en la ecuación general de la parábola , la tarea es encontrar la longitud del Latus Rectum de la parábola .
Ejemplos:
Entrada: a =3, b = 5, c = 1
Salida: 0,333333Entrada: a = 4, b = 0, c = 4
Salida: 0,25
Enfoque: El problema dado se puede resolver con base en las siguientes observaciones:
Observación:
- El Latus rectum de una parábola es la línea perpendicular al eje y al foco de la parábola y su longitud es igual a 4 veces la distancia entre el foco y el vértice de la parábola.
- Por lo tanto, la tarea se reduce a encontrar la distancia entre el foco y el vértice de la parábola usando la fórmula:
Siga los pasos a continuación para resolver el problema:
- Inicialice dos variables, digamos vértice y foco para almacenar las coordenadas del vértice y el foco de la parábola.
- Encuentra las coordenadas del vértice y el foco de la parábola y guárdalas en las variables correspondientes.
- Inicialice una variable, digamos length , y configúrela en 4 veces la distancia entre el vértice y el foco de la parábola.
- Imprime el valor de longitud como respuesta.
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 distance // between two points float distance(float x1, float y1, float x2, float y2) { // Calculating distance return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } // Function to calculate length of // the latus rectum of a parabola float lengthOfLatusRectum(float a, float b, float c) { // Stores the co-ordinates of // the vertex of the parabola pair<float, float> vertex = { (-b / (2 * a)), (((4 * a * c) - (b * b)) / (4 * a)) }; // Stores the co-ordinates of // the focus of parabola pair<float, float> focus = { (-b / (2 * a)), (((4 * a * c) - (b * b) + 1) / (4 * a)) }; // Print the distance between focus and vertex cout << 4 * distance( focus.first, focus.second, vertex.first, vertex.second); } // Driver Code int main() { // Given a, b & c float a = 3, b = 5, c = 1; // Function call lengthOfLatusRectum(a, b, c); return 0; }
Java
// Java program for the above approach class GFG{ static class pair { float first; float second; public pair(float first, float second) { this.first = first; this.second = second; } } // Function to calculate distance // between two points static float distance(float x1, float y1, float x2, float y2) { // Calculating distance return (float) Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } // Function to calculate length of // the latus rectum of a parabola static void lengthOfLatusRectum(float a, float b, float c) { // Stores the co-ordinates of // the vertex of the parabola pair vertex = new pair( (-b / (2 * a)), (((4 * a * c) - (b * b)) / (4 * a)) ); // Stores the co-ordinates of // the focus of parabola pair focus = new pair( (-b / (2 * a)), (((4 * a * c) - (b * b) + 1) / (4 * a)) ); // Print the distance between focus and vertex System.out.print(4 * distance( (float)focus.first, (float)focus.second, (float)vertex.first, (float)vertex.second)); } // Driver Code public static void main(String[] args) { // Given a, b & c float a = 3, b = 5, c = 1; // Function call lengthOfLatusRectum(a, b, c); } } // This code is contributed by 29AjayKumar
Python3
# Python 3 program for the above approach from math import sqrt # Function to calculate distance # between two points def distance(x1, y1, x2, y2): # Calculating distance return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) # Function to calculate length of # the latus rectum of a parabola def lengthOfLatusRectum(a, b, c): # Stores the co-ordinates of # the vertex of the parabola vertex = [(-b / (2 * a)), (((4 * a * c) - (b * b)) / (4 * a))] # Stores the co-ordinates of # the focus of parabola focus = [(-b / (2 * a)), (((4 * a * c) - (b * b) + 1) / (4 * a))] # Print the distance between focus and vertex print("{:.6f}".format(4 * distance(focus[0], focus[1], vertex[0], vertex[1]))) # Driver Code if __name__ == "__main__": # Given a, b & c a = 3 b = 5 c = 1 # Function call lengthOfLatusRectum(a, b, c) # This code is contributed by bgangwar59.
C#
// C# program for the above approach using System; public class GFG{ class pair { public float first; public float second; public pair(float first, float second) { this.first = first; this.second = second; } } // Function to calculate distance // between two points static float distance(float x1, float y1, float x2, float y2) { // Calculating distance return (float) Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } // Function to calculate length of // the latus rectum of a parabola static void lengthOfLatusRectum(float a, float b, float c) { // Stores the co-ordinates of // the vertex of the parabola pair vertex = new pair( (-b / (2 * a)), (((4 * a * c) - (b * b)) / (4 * a)) ); // Stores the co-ordinates of // the focus of parabola pair focus = new pair( (-b / (2 * a)), (((4 * a * c) - (b * b) + 1) / (4 * a)) ); // Print the distance between focus and vertex Console.Write(4 * distance( (float)focus.first, (float)focus.second, (float)vertex.first, (float)vertex.second)); } // Driver Code public static void Main(String[] args) { // Given a, b & c float a = 3, b = 5, c = 1; // Function call lengthOfLatusRectum(a, b, c); } } // This code is contributed by 29AjayKumar
Javascript
<script> // Javascript program for the above approach // Function to calculate distance // between two points function distance(x1, y1, x2, y2) { // Calculating distance return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } // Function to calculate length of // the latus rectum of a parabola function lengthOfLatusRectum(a, b, c) { // Stores the co-ordinates of // the vertex of the parabola let vertex = [ (-b / (2 * a)), (((4 * a * c) - (b * b)) / (4 * a)) ]; // Stores the co-ordinates of // the focus of parabola let focus = [ (-b / (2 * a)), (((4 * a * c) - (b * b) + 1) / (4 * a)) ]; // Print the distance between focus and vertex document.write((4 * distance( focus[0], focus[1], vertex[0], vertex[1])).toFixed(6)); } // Given a, b & c let a = 3, b = 5, c = 1; // Function call lengthOfLatusRectum(a, b, c); // This code is contributed by divyeshrabadiya07. </script>
Producción:
0.333333
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)