椭圆角计算和点计算的问题 [英] Issue with ellipse angle calculation and point calculation
问题描述
我有一个 UIView
,其边界为(w,h),我试图计算一个以视图中点为中心的椭圆的角度和点,即中心为( w * 0.5,h * 0.5)。我不断更改视图和椭圆的大小,以便从控制台获取以下值作为实例的值。
I have a UIView
with bounds (w, h) and I am trying to calculate angles and point on a ellipse which is centred at view's mid point i.e. centre is (w * 0.5, h * 0.5). I continuously change the size of view and ellipse so following values are from console for a instance of values.
在这种情况下,(w,h)=(150.000000,300.799988 )和半径为(rx,ry)=(52.500000,105.279999)
For this instance, (w, h) = (150.000000, 300.799988) and radii are (rx, ry) = (52.500000, 105.279999)
现在,我尝试查找点 P1(x,y )
(30.784275,93.637390)在椭圆上使用以下代码:
Now, I try to find angle of point P1(x,y)
(30.784275, 93.637390) on this ellipse using following code:
CGFloat angle = atan2((y - (h * 0.5)), (x - (w * 0.5)));
if (angle < 0)
{
angle += 2 * M_PI;
}
我得到的角度值是 4.050611
。
由于没有得到想要的输出,我只是尝试使用以下代码从上方角度在椭圆上找到该点:
Since I was not getting my desired output I just tried to find the point on ellipse from above angle using code below:
framePoint.x = (w * 0.5) + (rx * cosf(angle));
framePoint.y = (h * 0.5) + (ry * sinf(angle));
令人惊讶的是,我的分数是(42.737656,67.344543)。
And surprisingly I got point as (42.737656,67.344543).
我只是继续进行了相同过程的又一次迭代。我从上面的点计算角度,得到的角度为4.341885,从最新的角度得到的新点为(55.990501,52.263786)。
I just went ahead and did one more iteration of same process. I calculated angle from above point and got angle as 4.341885 and new point from this latest angle as (55.990501,52.263786).
我知道我的计算公式有问题,但是我无法指出。
I know something is wrong with my calculation formulas but I am not able to pin point it.
如果在椭圆上方是一个圆,即rx = ry时,所有点和角度都相等。因此,它适用于圆形而不适用于椭圆。
Also if above ellipse is a circle i.e. when rx = ry, all the points and angle are equal. So it kind of work for circle but not for ellipse.
所以,我想确切地知道我出了什么问题。
So, I want to know exactly where I went wrong.
推荐答案
是的,现在我明白了您的意思
yes now I see it what you mean
- 您正在获得
E
角从椭圆通过E = atan2(...)
从 - 并在需要
M的方程中使用它
anglex = x0 + rx * cos(M),y = ...
- M是平均圆角
- ,E为椭圆角
- 它类似于开普勒方程。
- 幸运的是,您不需要匹配速度主要重点是:
- you are obtaining
E
angle from ellipse viaE=atan2(...)
- and using it in equation where you need
M
anglex=x0+rx*cos(M), y=...
- M is mean circular angle
- and E is ellipse angle
- it is analogy to Kepler's equation.
- luckily for you you do not need to match speeds around main focus point so:
为了获得 M
角
- 您必须缩放一个轴以将椭圆转换为圆形
- 并在那里计算角度 >
- 因此,如果您的轴指定的椭圆为
(x0,y0,rx,ry)
- 并输入椭圆上的点是
(x1,y1)
- 然后,如果我没记错的话,它应该是这样的:
-
M = atan2((y1-y0)* rx / ry,x1-x0)
或M = atan2(y1-y0,(x1-x0) * ry / rx)
-
x = x0 + rx * cos(M)
-
y = y0 + ry * sin(M)
- you have to scale one axis to convert ellipse to circle
- and compute the angle there
- so if your axis alligned ellipse is
(x0,y0,rx,ry)
- and input point on ellipse is
(x1,y1)
- then if I am not mistaken it should be like this:
M=atan2((y1-y0)*rx/ry,x1-x0)
orM=atan2(y1-y0,(x1-x0)*ry/rx)
x=x0+rx*cos(M)
y=y0+ry*sin(M)
[notes]
- 两个点的X坐标应该相同(图像是用手绘颜料绘制的)
- 缩放哪个轴和哪个轴都没有关系
这篇关于椭圆角计算和点计算的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!