Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmFinding the vertex, focus and directrix of a parabola

Finding the vertex, focus and directrix of a parabola

Problem – Find the vertex, focus and directrix of a parabola when the coefficients of its equation are given.
A set of points on a plain surface that forms a curve such that any point on that curve is equidistant from the focus is a parabola. 
Vertex of a parabola is the coordinate from which it takes the sharpest turn whereas a is the straight line used to generate the curve. 
 

22

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 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=-198
Consult the formula below for explanation.

 

This problem is a simple example of implementations of formulae. Given below are the required set of formulae which will help us tackle the problem. 
 

For a parabola in the form y=ax^2+bx+cVertex: (-b/2a, 4ac-b^2/4a)Focus: (-b/2a, 4ac-b^2+1/4a)Directrix: y=c-(b^2+1)4a

 

C++




#include <iostream>
using namespace std;
 
// Function to calculate Vertex, Focus and Directrix
void parabola(float a, float b, float c)
{
    cout << "Vertex: (" << (-b / (2 * a)) << ", "
         << (((4 * a * c) - (b * b)) / (4 * a))
         << ")" << endl;
    cout << "Focus: (" << (-b / (2 * a)) << ", "
         << (((4 * a * c) - (b * b) + 1) / (4 * a))
         << ")" << endl;
    cout << "Directrix: y="
         << c - ((b * b) + 1) * 4 * a << endl;
}
 
// Driver Function
int main()
{
    float a = 5, b = 3, c = 2;
    parabola(a, b, c);
    return 0;
}


Java




// Java program to find the vertex,
// focus and directrix of a parabola
 
class GFG {
     
    // Function to calculate Vertex,
    // Focus and Directrix
    static void parabola(float a,
                         float b, float c)
    {
         
        System.out.println("Vertex: (" +
                          (-b / (2 * a)) + ", " +
                          (((4 * a * c) - (b * b)) /
                          (4 * a)) + ")");
                     
        System.out.println("Focus: (" +
                          (-b / (2 * a)) + ", "    +
                          (((4 * a * c) - (b * b) + 1) /
                          (4 * a)) + ")");
             
        System.out.println("Directrix:" + " y=" +
                          (int)(c - ((b * b) + 1) *
                          4 * a));
    }
 
    // Driver Function
    public static void main(String[] args)
    {
        float a = 5, b = 3, c = 2;
         
        // Function calling
        parabola(a, b, c);
    }
}
 
// This code is contributed by
// Smitha Dinesh Semwal


Python 3




# Function to calculate Vertex,
# Focus and Directrix
def parabola(a, b, c):
 
    print("Vertex: (" , (-b / (2 * a)),
        ", ", (((4 * a * c) - (b * b))
            / (4 * a)), ")", sep = "")
               
    print("Focus: (" , (-b / (2 * a)),
    ", ", (((4 * a * c) - (b * b) + 1)
            / (4 * a)), ")", sep = "")
                
    print("Directrix: y=", c - ((b * b)
                + 1) * 4 * a, sep = "")
 
# Driver Function
a = 5
b = 3
c = 2
parabola(a, b, c)
 
# This code is contributed by Smitha.


C#




// C# program to find the vertex,
// focus and directrix of a parabola
using System;
 
class GFG {
     
    // Function to calculate Vertex,
    // Focus and Directrix
    static void parabola(float a,
                         float b, float c)
    {
        Console.WriteLine("Vertex: (" +
                         (-b / (2 * a)) + ", " +
                         (((4 * a * c) - (b * b)) /
                         (4 * a)) + ")");
                     
        Console.WriteLine("Focus: (" +
                         (-b / (2 * a)) + ", " +
                         (((4 * a * c) - (b * b) + 1) /
                         (4 * a)) + ")");
                 
        Console.Write("Directrix:" + " y=" +
                     (int)(c - ((b * b) + 1) * 4 * a));
    }
 
    // Driver Function
    public static void Main()
    {
        float a = 5, b = 3, c = 2;
         
        // Function calling
        parabola(a, b, c);
    }
}
 
// This code is contributed by nitin mittal


PHP




<?php
// PHP program to Find the vertex,
// focus and directrix of a parabola
 
// Function to calculate Vertex,
// Focus and Directrix
function parabola($a, $b, $c)
{
     
    echo "Vertex: (" , (-$b / (2 * $a)) , ", ",
        (((4 * $a * $c) - ($b * $b)) / (4 * $a)),
                                      ")", "\n" ;
    echo "Focus: (" , (-$b / (2 * $a)) , ", ",
        (((4 * $a * $c) - ($b * $b) + 1) / (4 * $a))
                                        , ")"," \n" ;
    echo "Directrix: y=",
        $c - (($b * $b) + 1) * 4 * $a ;
}
 
    // Driver Code
    $a = 5; $b = 3; $c = 2;
    parabola($a, $b, $c);
     
// This code is contributed by vt_m.
?>


Javascript




<script>
 
// JavaScript program to find the vertex,
// focus and directrix of a parabola
 
    // Function to calculate Vertex,
    // Focus and Directrix
    function parabola(a, b, c)
    {
           
        document.write("Vertex: (" +
                          (-b / (2 * a)) + ", " +
                          (((4 * a * c) - (b * b)) /
                          (4 * a)) + ")" + "<br/>");
                       
       document.write("Focus: (" +
                          (-b / (2 * a)) + ", "    +
                          (((4 * a * c) - (b * b) + 1) /
                          (4 * a)) + ")" + "<br/>");
               
        document.write("Directrix:" + " y=" +
                          (c - ((b * b) + 1) *
                          4 * a) + "<br/>");
    }
 
// Driver code
 
        let a = 5, b = 3, c = 2;
           
        // Function calling
        parabola(a, b, c);
             
            // This code is contributed by code_hunt.
</script>


Output – 
 

Vertex:(-0.3, 1.55)
Focus: (-0.3, 1.6)
Directrix: y=-198

Time Complexity: O(1)

Auxiliary Space: O(1)
 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments