Python Program to Find Vertex, Focus and Directrix of Parabola

In the previous article, we have discussed Python Program to Print nth Iteration of Lucas Sequence
Parabola:

A parabola is a curve in a 2D plane that is the same distance from a fixed point called focus as a fixed straight line. The directrix is the name given to this line. A parabola’s general equation is y= ax2+bx+c. In this case, a, b, and c can be any real number.

Given a, b, c  values, the task is to determine Vertex, Focus, and Directrix of the above Given Parabola.

Examples:

Example 1 :

Input :

Given first Term = 5
Given second Term = 2
Given Third Term = 3

Output:

The Vertex of the above Given parabola = ( -0.2 ,  2.8 )
The Focus of the above Given parabola = ( -0.2 ,  2.85 )
The Directrix of the above Given parabola = -97

Example 2 :

Input :

Given first Term = 6
Given second Term = 3
Given Third Term = 1

Output:

The Vertex of the above Given parabola = ( -0.25 ,  0.625 )
The Focus of the above Given parabola = ( -0.25 ,  0.6666666666666666 )
The Directrix of the above Given parabola = -239

Program to Find Vertex, Focus and Directrix of Parabola

Below are the ways to find Vertex, Focus, and Directrix of Parabola.

Method #1: Using Mathematical Formula  (Static Input)

Approach:

  • Give the first number as static input and store it in a variable.
  • Give the second number as static input and store it in another variable.
  • Give the third number as static input and store it in another variable.
  • Print the vertex of the above-given parabola using Standard mathematical formulas.
  • Print the Focus of the above-given parabola using Standard mathematical formulas.
  • Print the Directrix of the above-given parabola using Standard mathematical formulas.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as static input and store it in a variable.
vertx = 5
# Give the second number as static input and store it in another variable.
focs = 2
# Give the third number as static input and store it in another variable.
dirctx = 3
# Print the vertex of the above given parabola using Standard mathematical formulas.
print("The Vertex of the above Given parabola = (", (-focs / (2 * vertx)),
      ", ", (((4 * vertx * dirctx) - (focs * focs)) / (4 * vertx)), ")")
# Print the Focus of the above given parabola using Standard mathematical formulas.
print("The Focus of the above Given parabola = (", (-focs / (2 * vertx)), ", ",
      (((4 * vertx * dirctx) - (focs * focs) + 1) / (4 * vertx)), ")")
# Print the Directrix of the above given parabola using Standard mathematical formulas.
print("The Directrix of the above Given parabola =", (int)
      (dirctx - ((focs * focs) + 1) * 4 * vertx))

Output:

The Vertex of the above Given parabola = ( -0.2 ,  2.8 )
The Focus of the above Given parabola = ( -0.2 ,  2.85 )
The Directrix of the above Given parabola = -97

Method #2: Using Mathematical Formula  (User Input)

Approach:

  • Give the first number as User input using the input() function and store it in a variable.
  • Give the second number as User input using the input() function and store it in another variable.
  • Give the third number as User input using the input() function and store it in another variable.
  • Print the vertex of the above-given parabola using Standard mathematical formulas.
  • Print the Focus of the above-given parabola using Standard mathematical formulas.
  • Print the Directrix of the above-given parabola using Standard mathematical formulas.
  • The Exit of the Program.

Below is the implementation:

# Give the first number as User input using the input() function  and store it in a variable.
vertx = int(input('Enter some Random Number = '))
# Give the second number as User input using the input() function  and store it in another variable.
focs =  int(input('Enter some Random Number = '))
# Give the third number as User input using the input() function  and store it in another variable.
dirctx =  int(input('Enter some Random Number = '))
# Print the vertex of the above given parabola using Standard mathematical formulas.
print("The Vertex of the above Given parabola = (", (-focs / (2 * vertx)),
      ", ", (((4 * vertx * dirctx) - (focs * focs)) / (4 * vertx)), ")")
# Print the Focus of the above given parabola using Standard mathematical formulas.
print("The Focus of the above Given parabola = (", (-focs / (2 * vertx)), ", ",
      (((4 * vertx * dirctx) - (focs * focs) + 1) / (4 * vertx)), ")")
# Print the Directrix of the above given parabola using Standard mathematical formulas.
print("The Directrix of the above Given parabola =", (int)
      (dirctx - ((focs * focs) + 1) * 4 * vertx))

Output:

Enter some Random Number = 6
Enter some Random Number = 3
Enter some Random Number = 1
The Vertex of the above Given parabola = ( -0.25 , 0.625 )
The Focus of the above Given parabola = ( -0.25 , 0.6666666666666666 )
The Directrix of the above Given parabola = -239

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.

Leave a Comment