- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a point is inside, outside or on the ellipse in C++
Suppose, one ellipse is given (the center coordinate (h, k) and semi-major axis a, and semi-minor axis b), another point is also given. We have to find whether the point is inside the ellipse or not. To solve it, we have to solve the following equation for the given point (x, y).
$$\frac{\left(x-h\right)^2}{a^2}+\frac{\left(y-k\right)^2}{b^2}\leq1$$
If the result is less than one, then the point is inside the ellipse, otherwise not.
Example
#include <iostream> #include <cmath> using namespace std; bool isInsideEllipse(int h, int k, int x, int y, int a, int b) { int res = (pow((x - h), 2) / pow(a, 2)) + (pow((y - k), 2) / pow(b, 2)); return res; } int main() { int x = 2, y = 1, h = 0, k = 0, a = 4, b = 5; if(isInsideEllipse(h, k, x, y, a, b) > 1){ cout <<"Outside Ellipse"; } else if(isInsideEllipse(h, k, x, y, a, b) == 1){ cout <<"On the Ellipse"; } else{ cout <<"Inside Ellipse"; } }
Output
Inside Ellipse
- Related Articles
- Check if a point is inside, outside or on the parabola in C++
- Check if a point lies on or inside a rectangle in Python
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Check if a given point lies inside a Polygon
- Check if points are inside ellipse faster than contains_point method (Matplotlib)
- Check if a circle lies inside another circle or not in C++
- How To Check if a Given Point Lies Inside a Rectangle in Java?
- JavaScript variables declare outside or inside loop?
- Find if a point lies inside a Circle in C++
- Program to check given point in inside or boundary of given polygon or not in python
- Check whether a given point lies inside a Triangle
- Check if Input, Output and Error is redirected on the Console or not in C#
- Check if a number is jumbled or not in C++
- Check if a Tree is Isomorphic or not in C++
- Check if a directed graph is connected or not in C++

Advertisements