# Finding the vertex, focus and directrix of a parabola in C++

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

In this tutorial, we are going to learn how to find the vertex, focus, and directrix of a parabola. We are given constants of the parabola equation x, y, and z.

There are straightforward formulas to find the vertex, focus, and directrix. Let's them.

Vertex − (-y/2x, 4xz-y^2/4x)

Focus − (-y/2x, 4xz-y^2+1/4x)

Directrix − z-(y^2+1)4x

## Example

Let's see the code.

Live Demo

#include <iostream>
using namespace std;
void findParabolaProperties(float x, float y, float z) {
cout << "Vertex: (" << -y/(2*x) << ", " << (((4*x*z) - (y*y))/4*x) << ")" << endl;
cout << "Focus: (" << -y/(2*x) << ", " << (((4*x*z) - (y*y)+1)/4*x) << ")" << endl;
cout << "Directrix: " << z-((y*y)+1)*4*x << endl;
}
int main() {
float x = 6, y = 4, z = 7;
findParabolaProperties(x, y, z);
return 0;
}

## Output

If you run the above code, then you will get the following result.

Vertex: (-0.333333, 228)
Focus: (-0.333333, 229.5)
Directrix: -401

## Conclusion

If you have any queries in the tutorial, mention them in the comment section

Updated on 29-Dec-2020 11:02:50