Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
C/C++ Program for Finding the vertex, focus and directrix of a parabola?
A parabola is a U-shaped curve that can be described by a quadratic equation. In C programming, we can find key properties of a parabola including its vertex, focus, and directrix using mathematical formulas. The general equation of a parabola is −
Syntax
y = ax² + bx + c
Where a, b, and c are coefficients and a ? 0.
Formulas
For a parabola y = ax² + bx + c, the key properties are calculated as −
- Vertex: (-b/(2a), (4ac - b²)/(4a))
- Focus: (-b/(2a), (4ac - b² + 1)/(4a))
- Directrix: y = (4ac - b² - 1)/(4a)
Example
This program calculates the vertex, focus, and directrix of a parabola given its coefficients −
#include <stdio.h>
void getParabolaDetails(float a, float b, float c) {
float vertex_x = -b / (2 * a);
float vertex_y = ((4 * a * c) - (b * b)) / (4 * a);
float focus_x = vertex_x;
float focus_y = vertex_y + (1 / (4 * a));
float directrix = vertex_y - (1 / (4 * a));
printf("Parabola equation: y = %.1fx² + %.1fx + %.1f\n", a, b, c);
printf("Vertex: (%.3f, %.3f)\n", vertex_x, vertex_y);
printf("Focus: (%.3f, %.3f)\n", focus_x, focus_y);
printf("Directrix: y = %.3f\n", directrix);
}
int main() {
float a = 1, b = -4, c = 3;
printf("Finding parabola properties:\n");
getParabolaDetails(a, b, c);
return 0;
}
Finding parabola properties: Parabola equation: y = 1.0x² + -4.0x + 3.0 Vertex: (2.000, -1.000) Focus: (2.000, -0.750) Directrix: y = -1.250
Key Points
- The vertex is the lowest (or highest) point of the parabola
- The focus is a point inside the parabola used for its geometric definition
- The directrix is a horizontal line that, together with the focus, defines the parabola
- For parabolas opening upward (a > 0), the focus is above the vertex
Conclusion
Using the standard quadratic equation coefficients, we can easily calculate the vertex, focus, and directrix of a parabola in C. These properties help visualize and analyze the parabola's geometric characteristics.
Advertisements
