📜  检查点是否在双曲线内、外或双曲线上

📅  最后修改于: 2021-10-23 08:34:20             🧑  作者: 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)

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程