- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 parabola in C++
Suppose, one parabola is given (the vertex coordinate (h, k) and distance from focus and vertex is a), another point is also given. We have to find whether the point is inside the parabola or not. To solve it, we have to solve the following equation for the given point (x, y)
\left(y-k\right)^2=4a\left(x-h\right)
If the result is less than 0, then this is present inside the parabola if it is 0, then it is on the parabola, and if greater than 0, then outside of the parabola.
Example
#include <iostream> #include <cmath> using namespace std; int isInsideParabola(int h, int k, int x, int y, int a) { int res = pow((y - k), 2) - 4 * a * (x - h); return res; } int main() { int x = 2, y = 1, h = 0, k = 0, a = 4; if(isInsideParabola(h, k, x, y, a) > 0){ cout <<"Outside Parabola"; } else if(isInsideParabola(h, k, x, y, a) == 0){ cout <<"On the Parabola"; } else{ cout <<"Inside Parabola"; } }
Output
Inside Parabola
Advertisements