如何在2D中找到一条线与椭圆相交的点(C#) [英] How to find a point where a line intersects an ellipse in 2D (C#)
问题描述
我需要找到一个点,其中一条线(它的原点是椭圆的中心)与2D中的椭圆相交...我可以很容易地找到圆上的一个点,因为我知道角度F和圆的半径( R):
x = x0 + R * cosF
y = y0 + R * sinF
code>
然而,我无法想象我该如何处理椭圆......我知道它是尺寸(A& B),但是找到参数T的方法是什么?!
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ x $ x $ A $ cosT $ b $ = y0 + B * sinT
从我所了解的参数T(T角度) F角度(在某些情况下约为-15度),但我无法计算出它的计算结果!!!
如果有一种善良的灵魂,请帮助我解决这个问题......
标准方程的椭圆,驻扎在0,0,是:
1 =(x)^ 2 /(a)+(y)^ 2 /(b)
其中a是水平轴上直径的1/2,而b是垂直轴上直径的1/2。
你有一条线,假设一个方程:
y =(m)( x - x0)+ y0
所以,让我们即插即用!
$ (b)$ b
1 =(x)^ 2 /(a)+(m(x - x0)+ y0)^ 2 / b
1 = x ^ 2 / a +(mx +(y0 - mx0))^ 2 / b
1 = x ^ 2 / a +(m ^ 2 * x ^ 2 + 2mx *(y0-mx0)+(y0-mx0)^ 2)/ b
1 = x ^ 2 / a +(m ^ 2 x ^ 2)/ b +(2mx *( ((x ^ 2 * b)/(a * b))+((y0-mx0)+(y0 ^ 2-2y0mx0 + m ^ 2 * x0 ^ 2))/ b
1 (m ^ 2 * x ^ 2 * a)/(a * b))+(2mxy0-2m ^ 2xx0)/ b +(y0 ^ 2-2y0mx0 + m ^ 2 * x0 ^ 2)/ b
1 =((bx ^ 2 + am ^ 2x ^ 2)/(ab))+(x *(2my0-2m ^ 2x0))/ b +(y0 ^ 2 - 2y0mx0 + m ^ 2 * x0 (b + a * m ^ 2)/(ab))+ x *((2my0-2m ^ 2x0)/ b)+( ((y0 ^ 2 - 2y0mx0 + m ^ 2 * x0 ^ 2)/ b) - 1)
最后一个方程遵循标准二次方程的形式。
因此,只需使用二次公式即可:
(( ((2my0-2m ^ 2x0)/ b)
和
(((y0 ^ 2 - 2y0mx0 + m ^ 2 * b + a * m ^ 2)/(ab))
x0 ^ 2)/ b) - 1)
得到交点处的X值;然后,将这些值插入您的原始方程式中以获得Y值。 祝您好运!
I need to find a point where a line (its origin is ellipse' center) intersects an ellipse in 2D... I can easily find a point on a circle, because I know an angle F and the circle' radius (R):
x = x0 + R * cosF
y = y0 + R * sinF
However I just can't figure how am I supposed to deal with an ellipse... I know it's dimensions (A & B), but what is the way of finding parameter T?!
x = x0 + A * cosT
y = y0 + B * sinT
From what I understand the parameter T (T angle) is not far from the F angle (approximately +-15 degrees in some cases), but I just can't figure how to calculate it!!!
If there is a kind hearted soul, please help me with this problem...
The standard equation of an ellipse, stationed at 0,0, is:
1 = (x)^2 / (a) + (y)^2 / (b)
Where a is 1/2 the diameter on the horizontal axis, and b is 1/2 the diameter on the vertical axis.
you have a line, assuming an equation:
y = (m)(x - x0) + y0
So, let us plug-and-play!
1 = (x)^2 / (a) + (m(x - x0) + y0)^2 / (b)
1 = x^2 / a + (mx + (y0 - mx0))^2 / b
1 = x^2 / a + (m^2 * x^2 + 2mx*(y0 - mx0) + (y0 - mx0)^2) / b
1 = x^2 / a + (m^2 x^2) / b + (2mx*(y0 - mx0) + (y0^2 - 2y0mx0 + m^2*x0^2)) / b
1 = ((x^2 * b) / (a * b)) + ((m^2 * x^2 * a) / (a * b)) + (2mxy0 - 2m^2xx0)/b + (y0^2 - 2y0mx0 + m^2*x0^2)/b
1 = ((bx^2 + am^2x^2)/(ab)) + (x*(2my0 - 2m^2x0))/b + (y0^2 - 2y0mx0 + m^2*x0^2)/b
0 = x^2*((b + a*m^2)/(ab)) + x*((2my0 - 2m^2x0)/b) + (((y0^2 - 2y0mx0 + m^2*x0^2)/b) - 1)
That last equation follows the form of a standard quadratic equation.
So just use the quadratic formula, with:
((b + a*m^2)/(ab))
((2my0 - 2m^2x0)/b)
and
(((y0^2 - 2y0mx0 + m^2*x0^2)/b) - 1)
to get the X values at the intersections; Then, plug in those values into your original line equation to get the Y values.
Good luck!
这篇关于如何在2D中找到一条线与椭圆相交的点(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!