Open In App

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

Last Updated : 06 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

A parabola is a U-shaped curve that can be either concave up or down, depending on the equation. Different properties of the parabola such as vertex, focus, the axis of symmetry, latus rectum, directrix, etc. are used to solve many problems throughout all the fields. 

Vertex of a Parabola

In the context of a parabola, the vertex is the point where the parabolic curve achieves its maximum or minimum value. It is the “highest” or “lowest” point on the graph, depending on whether the parabola opens upwards or downwards. The vertex lies exactly at the axis of symmetry, which is a vertical line passing through the vertex and parallel to the y-axis.

Focus of a Parabola

The focus of a parabola is a fixed point inside the parabola, equidistant from all points on the curve. It is a focal point where all the incoming rays parallel to the axis of symmetry (line passing through the vertex and perpendicular to the directrix) are reflected off and converged at the focus. The focus is located along the axis of symmetry and is represented by the coordinates (h, k), where h and k are the x and y coordinates of the focus, respectively.

Directrix of a Parabola

The directrix of a parabola is a straight line outside the parabola and is perpendicular to the axis of symmetry. It is located on the opposite side of the parabola compared to the focus. The directrix does not intersect the parabola. All points on the parabola are equidistant to both the focus and the directrix. The equation of the directrix is given by y = D, where D is the y-coordinate of the directrix.

The standard form of a parabola equation is y = ax^2 + bx + c.

Given the values of a, b, and c; our task is to find the coordinates of the vertex, focus, and the equation of the directrix.

Example:
Input : 5 3 2
Output : Vertex: (-0.3, 1.55)
         Focus:  (-0.3, 1.6)
         Directrix: y = -1.5

Program for Finding the Vertex, Focus, and Directrix of a Parabola

C




// C Program for Finding the vertex, focus and directrix of a parabola
#include <stdio.h>
 
int main()
{
    double a, b, c;
    a = 1, b = 4, c = 7;
   
    // Calculate the coordinates of the vertex
    double h = -b / (2.0 * a);
    double k = c - (b * b) / (4.0 * a);
 
    // Calculate the coordinates of the focus
    double p = h;
    double q = k + 1.0 / (4.0 * a);
 
    // Calculate the equation of the directrix
    double directrix = k - 1.0 / (4.0 * a);
 
    // Print the results
    printf("\nCoordinates of the Vertex: (%lf, %lf)", h, k);
 
    printf("\nCoordinates of the Focus: (%lf, %lf)", p, q);
 
    printf("\nEquation of the Directrix: y = %lf",
           directrix);
    return 0;
}


C++




// C++ Program for Finding the vertex, focus and directrix
// of a parabola
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    double a, b, c;
    a = 1, b = 2, c = -8;
 
    // Calculate the coordinates of the vertex
    double h = -b / (2.0 * a);
    double k = c - (b * b) / (4.0 * a);
 
    // Calculate the coordinates of the focus
    double p = h;
    double q = k + 1.0 / (4.0 * a);
 
    // Calculate the equation of the directrix
    double directrix = k - 1.0 / (4.0 * a);
 
    // Print the results
    cout << "\nCoordinates of the Vertex: (" << h << ", "
         << k << ")";
    cout << "\nCoordinates of the Focus: (" << p << ", "
         << q << ")";
    cout << "\nEquation of the Directrix: y = " << directrix
         << endl;
 
    return 0;
}


Output

Coordinates of the Vertex: (-2.000000, 3.000000)
Coordinates of the Focus: (-2.000000, 3.250000)
Equation of the Directrix: y = 2.750000


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads