The Wayback Machine - https://web.archive.org/web/20240823161812/https://www.geeksforgeeks.org/check-if-a-point-is-inside-outside-or-on-a-hyperbola/
Open In App

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

Last Updated : 25 Nov, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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):

  \frac{(x-h)^2}{a^2}  - \frac{(y-k)^2}{b^2}

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 <bits/stdc++.h>
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

<script>
 
// JavaScript program for the above approach
 
// Function to check if the point
// (x, y) lies inside, on or
// outside the given hyperbola
function checkpoint(h, k, x, y, a, b)
{
     
    // Stores the value of the equation
    p = ((Math.pow((x - h), 2) / Math.pow(a, 2)) -
         (Math.pow((y - k), 2) / Math.pow(b, 2)))
 
    // Generate output based on value of p
    if (p > 1)
        console.log("Outside");
     
    else if (p == 1)
        console.log("On the Hyperbola");
     
    else
        console.log("Inside");
}
 
// Driver Code
function main()
{
    var h = 0;
    var k = 0;
    var x = 2;
    var y = 1;
    var a = 4;
    var b = 5;
     
    checkpoint(h, k, x, y, a, b);
}
 
// main function call
main()
 
// This code is contributed by AnkThon
 
</script>

                    

Output: 
Inside

 

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


 



Similar Reads

Check if a point is inside, outside or on the ellipse
Given an ellipse centered at (h, k), with semi-major axis a, and semi-minor axis b, both aligned with the Cartesian plane. The task is to determine if the point (x, y) is within the area bounded by the ellipse. Examples:  Input: h = 0, k = 0, x = 2, y = 1, a = 4, b = 5 Output: InsideInput: h = 1, k = 2, x = 200, y = 100, a = 6, b = 5Output: Outside
10 min read
How to check if a given point lies inside or outside a polygon?
Given a polygon and a point 'p', find if 'p' lies inside the polygon or not. The points lying on the border are considered inside. Examples: Recommended ProblemPlease solve it on PRACTICE first, before moving on to the solution Solve ProblemApproach: The idea to solve this problem is based on How to check if two given line segments intersect, and t
9 min read
Check if a point is inside, outside or on the parabola
Given a parabola with vertex (h, k), and [Tex]a     [/Tex], the distance between focus and vertex. The task is to determine if the point (x, y) is inside, outside or on the parabola.Examples:   Input: h = 100, k = 500, x = 20, y = 10, a = 4 Output: OutsideInput: h = 0, k = 0, x = 2, y = 1, a = 4Output: Inside     Approach: It is very simple, we hav
5 min read
Find if a point lies inside, outside or on the circumcircle of three points A, B, C
Given four non-collinear points A, B, C, and P. The task is to find whether point P lies inside, outside or on the circumcircle formed by points A, B, and C.Examples Input: A = {2, 8}, B = {2, 1}, C = {4, 5}, P = {2, 4}; Output: Point (2, 4) is inside the circumcircle. Input: A = {2, 8}, B = {2, 1}, C = {4, 5}, P = {3, 0}; Output: Point (3, 0) lies
15+ min read
Check whether a point lies inside a sphere or not
Given co-ordinates of the center of a sphere (cx, cy, cz) and its radius r. Our task is to check whether a point (x, y, z) lies inside, outside or on this sphere.Examples: Input : Centre(0, 0, 0) Radius 3 Point(1, 1, 1) Output :Point is inside the sphere Input :Centre(0, 0, 0) Radius 3 Point(2, 1, 2) Output :Point lies on the sphere Input :Centre(0
7 min read
Check if a point lies inside a rectangle | Set-2
Given coordinates of bottom-left and top-right corners of a rectangle. Check if a point (x, y) lies inside this rectangle or not. Examples: Input: bottom-left: (0, 0), top-right: (10, 8), point: (1, 5) Output: Yes Input: bottom-left: (-1, 4), top-right:(2, 3), point:(0, 4) Output: No This problem is already discussed in a previous post. In this pos
6 min read
Check whether a given point lies on or inside the rectangle | Set 3
Given two numbers a and b where b &lt; a form a rectangle with points (0, b), (b, 0), (a-b, b), (b, a-b). Given a point (x, y), the task is to check whether this point lies inside or on the rectangle or not. Examples: Input: a = 7, b = 2, x = 5, y = 2; Output: Given point does not lie on the rectangle Input: a = 7, b = 2, x = 4, y = 5; Output: Give
6 min read
Check if the given point lies inside given N points of a Convex Polygon
Given coordinates of the N points of a Convex Polygon. The task is to check if the given point (X, Y) lies inside the polygon. Examples: Input: N = 7, Points: {(1, 1), (2, 1), (3, 1), (4, 1), (4, 2), (4, 3), (4, 4)}, Query: X = 3, Y = 2 Below is the image of plotting of the given points: Output: YES Input: N = 7, Points: {(1, 1), (2, 1), (3, 1), (4
15 min read
Check whether a given point lies inside a triangle or not
Given three corner points of a triangle, and one more point P. Write a function to check whether P lies within the triangle or not. Example: Input: A = (0, 0), B = (10, 30), C = (20, 0), P(10, 15)Output: InsideExplanation: B(10,30) / \ / \ / \ / P \ P' / \ A(0,0) ----------- C(20,0) Input: A = (0, 0), B = (10, 30), C = (20, 0), P(30, 15)Output: Out
15+ min read
Check whether a given point lies inside a rectangle or not
Given four points of a rectangle, and one more point P. Write a function to check whether P lies within the given rectangle or not.Examples:   Input : R = [(10, 10), (10, -10), (-10, -10), (-10, 10)] P = (0, 0)Output : yesIllustration : Input : R = [(10, 10), (10, -10), (-10, -10), (-10, 10)], P = (20, 20)Output : noIllustration : Prerequisite: Che
14 min read
Program to find the length of Latus Rectum of a Hyperbola
Given two integers A and B, representing the length of the semi-major and semi-minor axes of a Hyperbola, the task is to find the length of the latus rectum of the hyperbola. Examples: Input: A = 3, B = 2Output: 2.66666 Input: A = 6, B = 3Output: 3 Approach: The Latus Rectum of a hyperbola is the focal chord perpendicular to the major axis and the
4 min read
Program to find the Eccentricity of a Hyperbola
Given two integers A and B, representing the length of the semi-major and semi-minor axis of a Hyperbola of the equation (X2 / A2) - (Y2 / B2) = 1, the task is to calculate the eccentricity of the given hyperbola. Examples: Input: A = 3, B = 2Output: 1.20185Explanation:The eccentricity of the given hyperbola is 1.20185. Input: A = 6, B = 3Output: 1
4 min read
Rectangular Hyperbola
Rectangular Hyperbola is a hyperbola in which the transverse and conjugate axes are equal. i.e. in the case of rectangular hyperbola a = b = 1. The asymptote of the rectangular hyperbola is y = Âąx. Also, the asymptotes of a rectangular hyperbola are perpendicular. In this article, we will explore the rectangular hyperbola in depth along with its st
7 min read
Hyperbola - Equation, Definition & Properties
Hyperbola is one of the fundamental shapes in geometry formed by intersecting a right circular cone with a plane at an angle such that both halves of the cone are intersected. It is often encountered in both mathematics and real-world applications. Defined as the set of all points where the difference of the distances to two fixed points (called fo
14 min read
Find a point that lies inside exactly K given squares
Given an integer K and an array arr each of whose element x represents a square with two of its vertices as (0, 0) and (x, x). The task is to find a point which lies in exactly K squares. Examples: Input: arr[] = {1, 2, 3, 4}, K = 2 Output: (3, 3) The point (3, 3) lies inside 3rd and 4th square only. Input: arr[] = {8, 1, 55, 90}, K = 3 Output: (8,
3 min read
Make N pairs from Array as (X, Y) coordinate point that are enclosed inside a minimum area rectangle
Given a number N, and an array A[] of size 2N, the task is to make N pairs of these array elements and place them on an X-Y coordinate plane, such that they are enclosed inside a minimum area rectangle( with sides parallel to the X-axis and Y-axis) and print the area of the rectangle. Examples: Input: N = 4, A = {1, 4, 2, 5, 3, 6, 7, 8}Output: 9Exp
7 min read
Find if a point lies inside a Circle
Given a circle (coordinates of centre and radius) and a point (coordinate), find if the point lies inside or on the circle, or not. Examples : Input: x = 4, y = 4 // Given Point circle_x = 1, circle_y = 1, rad = 6; // Circle Output: Inside Input: x = 3, y = 3 // Given Point circle_x = 0, circle_y = 1, rad = 2; // Circle Output: Outside We strongly
5 min read
Triangle with no point inside
Given N points in 2-dimensional space, we need to find three points such that triangle made by choosing these points should not contain any other points inside. All given points will not lie on the same line so solution will always exist. Examples: In above diagram possible triangle with no point inside can be formed by choosing these triplets,[(0,
15+ min read
Find minimum radius such that atleast k point lie inside the circle
Given a positive integer K, a circle center at (0, 0) and coordinates of some points. The task is to find minimum radius of the circle so that at-least k points lie inside the circle. Output the square of the minimum radius. Examples: Input : (1, 1), (-1, -1), (1, -1), k = 3Output : 2We need a circle of radius at least 2to include 3 points.Input :
12 min read
Find intersection point of lines inside a section
Given N lines in two-dimensional space in y = mx + b form and a vertical section. We need to find out whether there is an intersection point inside the given section or not. Examples: In below diagram four lines are there, L1 : y = x + 2 L2 : y = -x + 7 L3 : y = -3 L4 : y = 2x – 7 and vertical section is given from x = 2 to x = 4 We can see that in
9 min read
Reflection of a point at 180 degree rotation of another point
Given two points coordinates (x1, y1) and (x2, y2)on 2D plane. The task is to find the reflection of (x1, y1) at 180 degree rotation of (x2, y2).Examples: Input : x1 = 0, y1 = 0, x2 = 1, y2 = 1 Output : (2, 2) Input : x1 = 1, y1 = 1, x2 = 2, y2 = 2 Output : (3, 3) Let the reflection point of point (x1, y1) about (x2, y2) be (x', y'). For (x', y') b
4 min read
Find time required to reach point N from point 0 according to given rules
Given two positive integers X and Y and N number of points arranged in a line, the task is to find the time required to reach point N from point 0 according to the following rules: Every point has one barrier that closes after every Y minutes and remains closed for the next Y minutes.On reaching a point if the barrier is closed, then the person nee
7 min read
Rotation of a point about another point
We have already discussed the rotation of a point P about the origin in the Set 1 and Set 2. The rotation of point P about origin with an angle ? in the anti-clockwise direction is given as under: Rotation of P about origin: P * polar(1.0, ?)Rotation of P about point Q Now, we have to rotate the point P not about origin but about a general point Q.
8 min read
Remove BST keys outside the given range
Given a Binary Search Tree (BST) and a range [min, max], remove all keys which are outside the given range. The modified tree should also be BST. Examples: Input : Output: Explanation: all keys outside the range [-10, 13] are removed and the modified tree is BST. Recommended PracticeRemove BST keys outside given rangeTry It! The idea is Fix the tre
10 min read
Minimum jumps to move outside the matrix
Given a grid of size NXN, some of the cells are vacant and some are blocked. We can move to any horizontally or vertically adjacent cell if the cell is vacant. Also, we can jump to a vacant cell in the 5×5 area centered at the square we are currently in. Starting from the cell (r1, c1), find the minimum number of jumps to reach cell (r2, c2). A vac
13 min read
Check if a given circle lies completely inside the ring formed by two concentric circles
Given two circles of radius r and R, both have their centre at the origin. Now, given another circle of radius r1 and centre at (x1, y1). Check, if the third circle(circle of radius r1) lies completely inside the ring formed by two circles of radius r and R.Examples : Input : r = 8 R = 4 r1 = 2 x1 = 6 y1 = 0 Output : yes Input : r = 8 R = 4 r1 = 2
6 min read
Check if a circle lies inside another circle or not
Given two circles with radii and centres given. The task is to check whether the smaller circle lies inside the bigger circle or not.  Examples:   Input: x1 = 10, y1 = 8, x2 = 1, y2 = 2, r1 = 30, r2 = 10 Output: The smaller circle lies completely inside the bigger circle without touching each other at a point of circumference. Input :x1 = 7, y1 = 8
6 min read
Check if it is possible to go from one point to another by choosing a Subsequence of steps of smallest length
Given a string S of characters R, L, U, D, along with integers X1, Y1, X2, Y2. In String S, 'R', 'L', 'U', and'D' denote right, left, up, and down steps from the current position. Then the task is to output the length of the smallest length subsequence of steps from S, such that following those steps we can reach from (X1, Y1) to (X2, Y2). If it is
9 min read
Check if it is possible to move from X to Z using point Y
Given three points X, Y, and Z of a 2D plane, the task is to check if it is possible to move from X to Z using point Y with at most one turn of 90 degrees. If possible return "YES" else return "NO". Note: Diagonal moves are not allowed, only vertical or horizontal moves are allowed. Examples: Input: X = {1, 3}, Y{4, 3}, Z = {4, 5}Output: YESExplana
13 min read
Check whether the given floating point number is a palindrome
Given a floating-point number N, the task is to check whether it is palindrome or not. Input: N = 123.321 Output: YesInput: N = 122.1 Output: No Approach: First, convert the given floating-point number into a character array.Initialize the low to first index and high to the last index.While low &lt; high: If the character at low is not equal to the
4 min read