C++ program to find the vertex, focus and directrix of a parabola

C++Server Side ProgrammingProgramming

In this article, we will be discussing a program to find the vertex, focus and directrix of a parabola when the coefficients of its equation is given.

Parabola is a curve whose all points on the curve are equidistant from a single point called focus.

As we know the general equation for a parabola is

y = ax2 + bx + c

For this equation, the following are defined as :

Vertex -(-b/2a, 4ac - b2/4a)
Focus - (-b/2a, 4ac - b2+1/4a)
Directrix - y = c - (b2 +1)4a

Example

 Live Demo

#include <iostream>
using namespace std;
void calc_para(float a, float b, float c) {
   cout << "Vertex- (" << (-b / (2 * a)) << ", " << (((4 * a* c) - (b * b)) / (4 * a)) << ")" << endl;
   cout << "Focus- (" << (-b / (2 * a)) << ", " << (((4 * a* c) - (b * b) + 1) / (4 * a)) << ")" << endl;
   cout << "Directrix- y=" << c - ((b * b) + 1) * 4 * a <<endl;
}
int main() {
   float a = 23, b = 34, c = 5;
   calc_para(a, b, c);
   return 0;
}

Output

Vertex- (-0.73913, -7.56522)
Focus- (-0.73913, -7.55435)
Directrix- y=-106439
raja
Published on 03-Oct-2019 12:16:49
Advertisements