📌  相关文章
📜  检查一个点是在双曲线的内部,外部还是在双曲线上

📅  最后修改于: 2021-04-17 15:57:34             🧑  作者: Mango

给定以(h,k)为中心的双曲线,且半长轴a和半短轴b均与笛卡尔平面对齐,任务是确定点(x,y)是否位于以是否双曲线。

例子:

方法:对于给定的点(x,y),可以通过解决下面提到的双曲线方程来解决给定的问题:

根据上述方程式的求值,程序的输出如下:

  • 小于1:该点位于双曲线内部
  • 等于1:位于双曲线
  • 大于1:该点位于双曲线之外

下面是上述方法的实现:

C++
// C++ program for the
// above approach
#include 
using namespace std;
 
// Function to check if the point
// (x, y) lies inside, on or
// outside the given hyperbola
void checkpoint(int h, int k, int x,
                int y, int a, int b)
{
 
    // Stores the value of the equation
    int p = (pow((x - h), 2) / pow(a, 2))
            - (pow((y - k), 2) / pow(b, 2));
 
    // Generate output based on value of p
    if (p > 1) {
        cout << "Outside";
    }
    else if (p == 1) {
        cout << "On the Hyperbola";
    }
    else {
        cout << "Inside";
    }
}
 
// Driver Code
int main()
{
    int h = 0, k = 0, x = 2;
    int y = 1, a = 4, b = 5;
 
    checkpoint(h, k, x, y, a, b);
 
    return 0;
}


Java
// Java program for the above approach
import java.io.*;
import java.lang.*;
import java.util.*;
 
class GFG{
 
// Function to check if the point
// (x, y) lies inside, on or
// outside the given hyperbola
static void checkpoint(int h, int k, int x,
                       int y, int a, int b)
{
     
    // Stores the value of the equation
    int p = (int)(Math.pow((x - h), 2) / Math.pow(a, 2)) -
            (int)(Math.pow((y - k), 2) / Math.pow(b, 2));
 
    // Generate output based on value of p
    if (p > 1)
    {
        System.out.println("Outside");
    }
    else if (p == 1)
    {
        System.out.println("On the Hyperbola");
    }
    else
    {
        System.out.println("Inside");
    }
}
 
// Driver Code
public static void main(String[] args)
{
    int h = 0, k = 0, x = 2;
    int y = 1, a = 4, b = 5;
 
    checkpoint(h, k, x, y, a, b);
}
}
 
// This code is contributed by Kingash


Python3
# Python3 program for the above approach
from math import pow
 
# Function to check if the point
# (x, y) lies inside, on or
# outside the given hyperbola
def checkpoint(h, k, x, y, a, b):
 
    # Stores the value of the equation
    p = ((pow((x - h), 2) // pow(a, 2)) -
         (pow((y - k), 2) // pow(b, 2)))
 
    # Generate output based on value of p
    if (p > 1):
        print("Outside")
     
    elif (p == 1):
        print("On the Hyperbola");
     
    else:
        print("Inside")
 
# Driver Code
if __name__ == "__main__":
 
    h = 0
    k = 0
    x = 2
    y = 1
    a = 4
    b = 5
 
    checkpoint(h, k, x, y, a, b)
 
# This code is contributed by AnkThon


C#
// C# program for the above approach
using System;
 
class GFG{
 
// Function to check if the point
// (x, y) lies inside, on or
// outside the given hyperbola
static void checkpoint(int h, int k, int x,
                       int y, int a, int b)
{
     
    // Stores the value of the equation
    int p = (int)(Math.Pow((x - h), 2) / Math.Pow(a, 2)) -
            (int)(Math.Pow((y - k), 2) / Math.Pow(b, 2));
 
    // Generate output based on value of p
    if (p > 1)
    {
        Console.WriteLine("Outside");
    }
    else if (p == 1)
    {
        Console.WriteLine("On the Hyperbola");
    }
    else
    {
        Console.WriteLine("Inside");
    }
}
 
// Driver Code
public static void Main(string[] args)
{
    int h = 0, k = 0, x = 2;
    int y = 1, a = 4, b = 5;
 
    checkpoint(h, k, x, y, a, b);
}
}
 
// This code is contributed by ukasp


Javascript


输出:
Inside

时间复杂度: O(1)
辅助空间: O(1)