VOOZH about

URL: https://www.geeksforgeeks.org/dsa/equation-of-ellipse-from-its-focus-directrix-and-eccentricity/

⇱ Equation of ellipse from its focus, directrix, and eccentricity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Equation of ellipse from its focus, directrix, and eccentricity

Last Updated : 23 Jul, 2022

Given focus(x, y), directrix(ax + by + c) and eccentricity e of an ellipse, the task is to find the equation of ellipse using its focus, directrix, and eccentricity.
Examples: 
 

Input: x1 = 1, y1 = 1, a = 1, b = -1, c = 3, e = 0.5
Output: 1.75 x^2 + 1.75 y^2 + -5.50 x + -2.50 y + 0.50 xy + 1.75 = 0

Input: x1 = -1, y1 = 1, a = 1, b = -1, c = 3, e = 0.5
Output: 1.75 x^2 + 1.75 y^2 + 2.50 x + -2.50 y + 0.50 xy + 1.75 = 0 


 


 

👁 Image


Let P(x, y) be any point on the ellipse whose focus S(x1, y1), directrix is the straight line ax + by + c = 0 and eccentricity is e. 
Draw PM perpendicular from P on the directrix. Then by definition of ellipse distance SP = e * PM => SP^2 = (e * PM)^2
 

(x - x1)^2 + (y - y1)^2 = e * ( ( a*x + b*y + c ) / (sqrt( a*a + b*b )) ) ^ 2
let ( a*a + b*b ) = t
x^2 + x1^2 - 2*x1*x + y^2 + y1^2 - 2*y1*y = e * ( ( a*x + b*y + c ) ^ 2 )/ t


on cross multiplying above we get
 

t*x^2 + t*x1^2 - 2*t*x1*x + t*y^2 + t*y1^2 - 2*t*y1*y = e * ( ( a*x + b*y + c ) ^ 2 )
t*x^2 + t*x1^2 - 2*t*x1*x + t*y^2 + t*y1^2 - 2*t*y1*y = e*a^2*x^2 + e*b^2*y^2 + 2*e*a*x*b*y + e*c^2 + 2*e*c*(a*x + b*y)
t*x^2 + t*x1^2 - 2*t*x1*x + t*y^2 + t*y1^2 - 2*t*y1*y = e*a^2*x^2 + e*b^2*y^2 + 2*e*a*x*b*y + e*c^2 + 2*e*c*a*x + 2*e*c*b*y
t*x^2 - e*a^2*x^2 + t*y^2 - e*b^2*y^2 - 2*t*x1*x - 2*e*c*a*x - 2*t*y1*y - 2*e*c*b*y - 2*e*a*x*b*y - e*c^2 + t*x1^2 + t*y1^2 =0
 


This can be compared with a general form that is: 
 

a*x^2 + 2*h*x*y + b*y^2 + 2*g*x + 2*f*y + c = 0


Below is the implementation of the above approach: 
 


Output: 
Equation of ellipse is 
1.75 x^2 + 1.75 y^2 + -5.50 x + -2.50 y + 0.50 xy + 1.75 = 0

 

Time Complexity: O(1)

Auxiliary Space: O(1)

Comment
Article Tags: