C/C++ Program for Finding the vertex, focus and directrix of a parabola?

CServer Side ProgrammingProgrammingC++

Here we will see how to find the vertex, focus directrix of a parabola using C or C++ program. To get these parameters we need the general equation of a parabola. The general formula is −

𝑦 = 𝑎𝑥+ 𝑏𝑥 + 𝑐

The values of a, b and c are given.

The formula for the vertex −

The formula for the focus −

The formula for the Directrix - y −

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
void getParabolaDetails(float a, float b, float c) {
   cout << "The vertex: (" << (-b / (2 * a)) << ", " << (((4 * a * c) - (b * b)) / (4 * a)) << ")" << endl;
   cout << "The Focus: (" << (-b / (2 * a)) << ", " << (((4 * a * c) - (b * b) + 1) / (4 * a)) << ")" << endl;
   cout << "y-Directrix:" << c - ((b * b) + 1) * 4 * a << endl;
}
main() {
   float a = 10, b = 3, c = 4;
   getParabolaDetails(a, b, c);
}

Output

The vertex: (-0.15, 3.775)
The Focus: (-0.15, 3.8)
y-Directrix:-396
raja
Published on 26-Jul-2019 07:47:20
Advertisements