我需要找到圆周与椭圆相交的点。
椭圆方程为:
((x-x1)^2)/(a*a)+((y-y1)^2)/(b*b)=1
圆周方程为:
(x-x0)^2+(y-y0)^2=r*r
,其中(x0,y0)和(x1,y1) - 是数字的中心。
我一直试图使用上面的公式找到(x,y)交点,但卡住了。
此外,我试图在谷歌上找到关于这个主题的内容。 Google用几种解决方案回答了我,但所有这些解决方案都远非逻辑完整。
如果有人已经解决了这个问题请帮助。
答案 0 :(得分:0)
您可以从这个solution开始:
public class Ellipse
{
public double x { get; set; }
public double y { get; set; }
public double a { get; set; }
public double b { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
var el1 = new Ellipse { x = 10, y = 4, a = 5, b = 2 };
var el2 = new Ellipse { x = 9, y = 4, a = 2, b = 3 };
var Xmin = Math.Max(el1.x - el1.a, el2.x - el2.a);
var Xmax = Math.Min(el1.x + el1.a, el2.x + el2.a);
var step = 0.01;
var accuracy = 0.01;
Func<Ellipse, double, List<double>> calculateY = (el, x) => {
var shift = el.b * Math.Sqrt(1 - Math.Pow((x - el.x) / el.a, 2));
return new List<double> { el.y - shift, el.y + shift };
};
var result = new List<List<double>>();
for(double i = Xmin; i <= Xmax; i += step)
{
var left = calculateY(el1, i);
var right = calculateY(el2, i);
foreach(var l in left)
foreach (var r in right)
if(Math.Abs(l - r) < accuracy)
result.Add(new List<double> { i, (l + r) / 2 });
}
foreach(var res in result)
Console.WriteLine(string.Format("x = {0}, y = {1}", res.First(), res.Last()));
}
}