C/C++ Program for Finding the vertex, focus and directrix of a parabola
Last Updated :
12 Aug, 2024
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 <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;
}
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;
}
OutputCoordinates of the Vertex: (-2.000000, 3.000000)
Coordinates of the Focus: (-2.000000, 3.250000)
Equation of the Directrix: y = 2.750000
Similar Reads
Program to find the Area of an Ellipse Given an ellipse with a semi-major axis of length a and semi-minor axis of length b. The task is to find the area of an ellipse.In mathematics, an ellipse is a curve in a plane surrounding by two focal points such that the sum of the distances to the two focal points is constant for every point on t
4 min read
C++ Implementation of Scaling in Computer Graphics In terms of computer graphics, Scaling is a process used for altering the size of objects. It changes the coordinate point of the original object. Modifying the object's size with the help of the object's dimension is dependent on the scaling factor(S). The scaling factor determines whether the obje
2 min read
Line Intersection in C++ Line Intersection in C++ is a problem that involves finding the point of intersection of two lines. For given points X and Y that corresponds to line XY and points A and B that corresponds to line AB the task is to find whether two lines (XY and AB) intersect and find the intersection point if they
4 min read
hypot(), hypotf(), hypotl() in C++ The hypot() function in C++ returns the square root of sum of square of arguments passed. It finds the hypotenuse, hypotenuse is the longest side of a right angled triangle. It is calculated by the formula : h = sqrt(x2+y2)where x and y are the other two sides of the triangle. Syntax:double hypot(do
3 min read
Convex Hull Algorithm in C++ The Convex Hull problem is fundamental problem in computational geometry. In this, we need to find the smallest convex polygon, known as the convex hull, that can include a given set of points in a two-dimensional plane. This problem has various applications in areas such as computer graphics, geogr
15+ min read
C++ Program to Find Diagonal of a Rectangle Given two positive integers i.e, the length and breadth of the rectangle, the task is to find the length of the Diagonal of a Rectangle. Example: Input: length=4 breadth=3 output: The Diagonal is 5 The diagonal of a rectangle is sqrt (a*a+ b*b) C++ // C++ Program to Find Diagonal of a Rectangle #inc
1 min read