Dada una parábola con vértice (h, k) , y , la distancia entre el foco y el vértice. La tarea es determinar si el punto (x, y) está dentro, fuera o sobre la parábola.
Ejemplos :
Input: h = 100, k = 500, x = 20, y = 10, a = 4 Output: Outside Input: h = 0, k = 0, x = 2, y = 1, a = 4 Output: Inside
Enfoque : es muy simple, solo tenemos que resolver la ecuación para el punto (x, y):
(yk)^2 = 4a(xh)
o, (yk)^2 – 4a(xh) = 0
Después de resolver, si el resultado es menor que 0 , entonces el punto se encuentra dentro , de lo contrario, si es exactamente 0 , entonces el punto se encuentra en la parábola , y si el resultado es mayor que 0 , el punto se encuentra fuera de la parábola .
Aquí estamos tomando una parábola cuyo eje de simetría es y = k , aunque el enfoque es aplicable para cualquier parábola.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to check if the point // lies within the parabola or not #include <bits/stdc++.h> using namespace std; // Function to check the point int checkpoint(int h, int k, int x, int y, int a) { // checking the equation of // parabola with the given point int p = pow((y - k), 2) - 4 * a * (x - h); return p; } // Driver code int main() { int h = 0, k = 0, x = 2, y = 1, a = 4; if (checkpoint(h, k, x, y, a) > 0) cout << "Outside" << endl; else if (checkpoint(h, k, x, y, a) == 0) cout << "On the parabola" << endl; else cout << "Inside" << endl; return 0; }
Java
// Java Program to check if the point // lies within the parabola or not class solution { // Function to check the point static int checkpoint(int h, int k, int x, int y, int a) { // checking the equation of // parabola with the given point int p =(int) Math.pow((y - k), 2) - 4 * a * (x - h); return p; } //driver code public static void main(String arr[]) { int h = 0, k = 0, x = 2, y = 1, a = 4; if (checkpoint(h, k, x, y, a) > 0) System.out.println("Outside"); else if (checkpoint(h, k, x, y, a) == 0) System.out.println("On the parabola"); else System.out.println("Inside"); } }
Python3
# Python3 Program to check if the point # lies within the parabola or not # Function to check the point def checkpoint(h, k, x, y, a): # checking the equation of # parabola with the given point p = pow((y - k), 2) - 4 * a * (x - h) return p # Driver code if __name__ == "__main__" : h = 0 k = 0 x = 2 y = 1 a = 4 if checkpoint(h, k, x, y, a) > 0: print ("Outside\n") elif checkpoint(h, k, x, y, a) == 0: print ("On the parabola\n") else: print ("Inside\n"); # This code is contributed by # Surendra_Gangwar
C#
// C# Program to check if the point // lies within the parabola or not using System; class GFG { // Function to check the point public static int checkpoint(int h, int k, int x, int y, int a) { // checking the equation of // parabola with the given point int p = (int) Math.Pow((y - k), 2) - 4 * a * (x - h); return p; } // Driver code public static void Main(string[] arr) { int h = 0, k = 0, x = 2, y = 1, a = 4; if (checkpoint(h, k, x, y, a) > 0) { Console.WriteLine("Outside"); } else if (checkpoint(h, k, x, y, a) == 0) { Console.WriteLine("On the parabola"); } else { Console.WriteLine("Inside"); } } } // This code is contributed // by Shrikant13
PHP
<?php // PHP Program to check if // the point lies within // the parabola or not // Function to check the point function checkpoint($h, $k, $x, $y, $a) { // checking the equation of // parabola with the given point $p = pow(($y - $k), 2) - 4 * $a * ($x - $h); return $p; } // Driver code $h = 0; $k = 0; $x = 2; $y = 1; $a = 4; if (checkpoint($h, $k, $x, $y, $a) > 0) echo "Outside"; else if (checkpoint($h, $k, $x, $y, $a) == 0) echo "On the parabola"; else echo "Inside"; // This code is contributed // by inder_verma ?>
Javascript
<script> // javascript Program to check if the point // lies within the parabola or not // Function to check the point function checkpoint(h , k , x , y , a) { // checking the equation of // parabola with the given point var p =parseInt(Math.pow((y - k), 2) - 4 * a * (x - h)); return p; } //driver code var h = 0, k = 0, x = 2, y = 1, a = 4; if (checkpoint(h, k, x, y, a) > 0) document.write("Outside"); else if (checkpoint(h, k, x, y, a) == 0) document.write("On the parabola"); else document.write("Inside"); // This code is contributed by 29AjayKumar </script>
Inside
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA