📜  椭圆的焦点、准线和偏心率方程

📅  最后修改于: 2021-10-23 08:17:04             🧑  作者: Mango

给定一个椭圆的焦点(x, y)、准线(ax + by + c)和偏心度e ,任务是使用椭圆的焦点、准线和偏心度找到椭圆的方程。
例子:

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 

设 P(x, y) 为焦点为 S(x1, y1) 的椭圆上的任意点,准线为直线 ax + by + c = 0,偏心率为 e。
在准线上从 P 垂直绘制 PM。然后根据椭圆距离的定义 SP = e * PM => SP^2 = (e * PM)^2

在上面的交叉乘法中我们得到

这可以与以下一般形式进行比较:

下面是上述方法的实现:

C++
// C++ program to find equation of an ellipse
// using focus and directrix.
#include 
#include 
#include 
#include 
 
using namespace std;
 
// Function to find equation of ellipse.
void equation_ellipse(float x1, float y1,
                      float a, float b,
                      float c, float e)
{
    float t = a * a + b * b;
    float a1 = t - e * (a * a);
    float b1 = t - e * (b * b);
    float c1 = (-2 * t * x1) - (2 * e * c * a);
    float d1 = (-2 * t * y1) - (2 * e * c * b);
    float e1 = -2 * e * a * b;
    float f1 = (-e * c * c) + (t * x1 * x1) + (t * y1 * y1);
 
    cout << fixed;
    cout << setprecision(2);
    cout << "Equation of ellipse is \n"
         << a1
         << " x^2 + " << b1 << " y^2 + "
         << c1 << " x + " << d1 << " y + "
         << e1 << " xy + " << f1 << " = 0";
}
 
// Driver Code
int main()
{
    float x1 = 1, y1 = 1, a = 1, b = -1, c = 3, e = 0.5 * 0.5;
    equation_ellipse(x1, y1, a, b, c, e);
 
    return 0;
}


Java
// Java program to find equation of an ellipse
// using focus and directrix.
import java.util.*;
 
class solution
{
 
// Function to find equation of ellipse.
static void equation_ellipse(float x1, float y1,
                    float a, float b,
                    float c, float e)
{
    float t = a * a + b * b;
    float a1 = t - e * (a * a);
    float b1 = t - e * (b * b);
    float c1 = (-2 * t * x1) - (2 * e * c * a);
    float d1 = (-2 * t * y1) - (2 * e * c * b);
    float e1 = -2 * e * a * b;
    float f1 = (-e * c * c) + (t * x1 * x1) + (t * y1 * y1);
 
    System.out.println("Equation of ellipse is ");
    System.out.print(a1+" x^2 + "+ b1 + " y^2 + "+ c1 + " x + "
                    + d1 + " y + " + e1 + " xy + " + f1 + " = 0");
         
}
 
// Driver Code
public static void main(String arr[])
{
    float x1 = 1, y1 = 1, a = 1, b = -1, c = 3, e = (float)0.5 * (float)0.5;
    equation_ellipse(x1, y1, a, b, c, e);
 
}
}
 
//This code is contributed by Surendra_Gaangwar


Python3
# Python3 program to find equation of an ellipse
# using focus and directrix.
 
# Function to find equation of ellipse.
def equation_ellipse(x1, y1, a, b, c,  e) :
     
    t = a * a + b * b
    a1 = t - e * (a * a)
    b1 = t - e * (b * b)
    c1 = (-2 * t * x1) - (2 * e * c * a)
    d1 = (-2 * t * y1) - (2 * e * c * b)
    e1 = -2 * e * a * b
    f1 = (-e * c * c) + (t * x1 * x1) + (t * y1 * y1)
 
    print("Equation of ellipse is",a1,"x^2 +", b1 ,"y^2 +",
    c1, "x +" ,d1 ,"y +", e1 ,"xy +" , f1 ,"= 0")
  
 
# Driver Code
if __name__ == "__main__" :
 
    x1, y1, a, b, c, e = 1, 1, 1, -1, 3, 0.5 * 0.5
     
    equation_ellipse(x1, y1, a, b, c, e)
 
# This code is contributed by Ryuga


C#
// C# program to find equation of an ellipse
// using focus and directrix.
 
class solution
{
 
// Function to find equation of ellipse.
static void equation_ellipse(float x1, float y1,
                    float a, float b,
                    float c, float e)
{
    float t = a * a + b * b;
    float a1 = t - e * (a * a);
    float b1 = t - e * (b * b);
    float c1 = (-2 * t * x1) - (2 * e * c * a);
    float d1 = (-2 * t * y1) - (2 * e * c * b);
    float e1 = -2 * e * a * b;
    float f1 = (-e * c * c) + (t * x1 * x1) + (t * y1 * y1);
 
    System.Console.WriteLine("Equation of ellipse is ");
    System.Console.WriteLine(a1+" x^2 + "+ b1 + " y^2 + "+ c1 + " x + "
                    + d1 + " y + " + e1 + " xy + " + f1 + " = 0");
         
}
 
// Driver Code
public static void Main()
{
    float x1 = 1, y1 = 1, a = 1, b = -1, c = 3, e = (float)0.5 * (float)0.5;
    equation_ellipse(x1, y1, a, b, c, e);
 
}
}
 
//This code is contributed by mits


PHP


Javascript


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