# Python program to find vertex, focus and directrix of parabola

In this tutorial, we will learn how to find vertex, focus and directrix of parabola in Python.

**What is a parabola?**

A parabola is a curve in a 2D plane such that every point on that plane is at the same distance from a fixed point called focus as from a fixed straight line. This line is called the directrix. A general equation of a parabola is y= px^{2}+qx+r. Here p, q, and r can be any real number.

In this tutorial, we will be given values of p, q, and r for the equation and we will have to find the vertex, focus and the equation of directrix. Let’s see how we can do this.

## Python program to calculate the vertex, focus, and directrix of a parabola

We can calculate the vertex and the focus of a parabola using formulae for them. We can also find the equation of the directrix as shown in the code. The below program calculates the vertex, focus and the directrix of a parabola with given coefficients p, q, and r. See the code.

def parabola(p, q, r): print("Vertex of the parabola is (", (-q/(2*p)) , "," , (((4*p*r)-(q*q))/(4*p)) , ")" ) print("Focus of the parabola is (", (-q/(2*p)) , "," , (((4*p*r)-(q*q)+1)/(4*p)) , ")" ) print("Equation of the directrix is y = ", (int)(r-((q*q)+1)*4*p)) p = 2 q = 4 r = 6 parabola(p, q, r)

The output of the above example program is given below.

Vertex of the parabola is ( -1.0 , 4.0 ) Focus of the parabola is ( -1.0 , 4.125 ) Equation of the directrix is y = -130

You can change the values of p, q, and r for different outputs.

Note that the above code only works for the parabola of the form y= px^{2}+qx+r. For the parabola of the form x= py^{2}+qy+r, we need to use different formulae.

Thank you.

Also, read: How to plot ROC Curve using Sklearn library in Python

## Leave a Reply