# Check if a point is inside, outside or on a Hyperbola

• Difficulty Level : Medium
• Last Updated : 25 Nov, 2021

Given a hyperbola centered at (h, k), with semi-major axis a, semi-minor axis b, both aligned with the Cartesian plane, the task is to determine if the point (x, y) lies within the area bounded by the hyperbola or not. Examples:

Input: h = 0, k = 0, x = 2, y = 1, a = 4, b = 5
Output: Inside

Input: h = 1, k = 2, x = 200, y = 100, a = 6, b = 5
Output: Outside

Approach: The given problem can be solved by solving the equation of hyperbola mentioned below, for the given point (x, y): Based on the evaluated value of the above equation, the output of the program is as follows:

• Less than 1: The point lies inside the hyperbola.
• Equal to 1: The point lies on the hyperbola
• Greater than 1: The point lies outside the hyperbola.

Below is the implementation of the above approach:

## 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 hyperbolavoid 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 Codeint 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 approachimport 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 hyperbolastatic 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 Codepublic 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 approachfrom math import pow # Function to check if the point# (x, y) lies inside, on or# outside the given hyperboladef 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 Codeif __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 approachusing System; class GFG{ // Function to check if the point// (x, y) lies inside, on or// outside the given hyperbolastatic 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 Codepublic 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

 

Output:

Inside

Time Complexity: O(1)
Auxiliary Space: O(1)

My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.5781762,"math_prob":0.9988418,"size":4350,"snap":"2022-27-2022-33","text_gpt3_token_len":1546,"char_repetition_ratio":0.124942474,"word_repetition_ratio":0.35873017,"special_character_ratio":0.39057472,"punctuation_ratio":0.20546558,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9997756,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-25T02:37:32Z\",\"WARC-Record-ID\":\"<urn:uuid:d306b2ee-f715-45a6-9469-9469f9356f3b>\",\"Content-Length\":\"165975\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cdc854c2-7644-4eca-b5bd-accec2e15fdc>\",\"WARC-Concurrent-To\":\"<urn:uuid:448e50b7-d3e0-4994-bbdf-734739de0abe>\",\"WARC-IP-Address\":\"23.12.145.47\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/check-if-a-point-is-inside-outside-or-on-a-hyperbola/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:J7YZQOI6SYO36HKW2GOCABNWBFU65TCI\",\"WARC-Block-Digest\":\"sha1:O6ON5O6HDML74G6FXWYIKAQ7ELUD2VT3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103033925.2_warc_CC-MAIN-20220625004242-20220625034242-00727.warc.gz\"}"}