我需要一个等式来沿着椭圆运动 [英] I need an equation for equal movement along an ellipse
问题描述
我正在编写类似行星绕太阳运动的程序,并且要使用函数来移动行星
i am programing something like planets moving around the Sun, and to move planets i am using a function
CGPointMake(object.center.x + 1, sqrt(75*75*150*150 - 75*75*(object.center.x - 300)*(object.center.x - 300))/150 + 150)
使用椭圆方程,其中a = 150,b = 75,p = 300,q = 150,但是当对象接近x = 450左右时,其速度会上升,我想这是由于pitagora所致,因为它经过的路径是c = sqrt((x-x0)^ 2 *(y-y0)^ 2)
using eliptic equation where a = 150, b = 75, p = 300, q = 150, but when object closes to x = around 450 its speed rises, i guess that is because of pitagora because the path its passes is c = sqrt((x-x0)^2*(y-y0)^2)
我注意到我的c总是在0.5左右,但是当它到达x域的末端时,它会上升到0.8,所以我需要一个程序或数学的解决方案来使对象绕椭圆曲线以相同的速度移动
i notice my c is always around 0.5, but when it gets on the end of x domain it rises up to 0.8 so i need either a programatic or mathematical solution to make object move at same speed around an eliptic curve
谢谢!
推荐答案
如果您想要真实的东西
然后,靠近主焦点(恒星系统的质量中心...与恒星非常接近的恒星)的行星移动得更快,因此请使用我的C ++实现.不要忘记查看该答案中的所有子链接,您可以在其中找到所需的一切.
then the planets closer to the primary focus point (center of mass of stellar system ... very close to star) are moving faster so use Kepler's equation here: C++ implementation of mine. Do not forget to check out all the sub-links in that answer you can find there everything you need.
如果要改用恒定速度
然后使用参数化椭圆方程
Then use parametric ellipse equation
x(a)=x0+rx*cos(a)
y(a)=y0+ry*sin(a)
其中a
是角度<0,2.0*PI>
(x0,y0)
是椭圆中心,而(rx,ry)
是椭圆半轴(半径).
where a
is angle <0,2.0*PI>
(x0,y0)
is the ellipse center and (rx,ry)
are the ellipse semi axises (radii).
如果a
以恒定速度递增,则面积增加是恒定的,因此a
是平均圆角,而不是椭圆形上的可见!有关更多信息,请点击此处:
if a
is incremented with constant speed then the area increase is constant so the a
is the mean circular angle not the visual on ellipse !!! For more info look here:
[edit1],因为MartinR指出速度不是恒定的
所以这是他的速度公式的近似值.椭圆与轴对齐,由x0,y0,rx,ry
(rx>=ry)
周边近似值l
:
so here is approximation with his formula for speed. Ellipse is axis aligned defined by x0,y0,rx,ry
(rx>=ry)
the perimeter aproximation l
:
h=(rx-ry)/(rx+ry); h*=3.0*h; l=M_PI*(rx+ry)*(1.0+(h/(10.0+sqrt(4.0-h))));
如果您希望沿周长有n
个大小相等的台阶,那么
if you want to have n
chunks of equal sized steps along the perimeter then
l/=n;
初始计算:
double x0,y0,rx,ry,n,l,h;
x0=Form1->ClientWidth>>1; // center is centered on form
y0=Form1->ClientHeight>>1;
rx=200; // semiaxises rx>=ry !!!
ry=75;
n=40.0; // number of chunks per ellipse (1/speed)
//l=2.0*M_PI*sqrt(0.5*((rx*rx)+(ry*ry))); // not accurate enough
h=(rx-ry)/(rx+ry); h*=3.0*h; l=M_PI*(rx+ry)*(1.0+(h/(10.0+sqrt(4.0-h)))); // this is more precise
l/=n; // single step size in units,pixels,or whatever
首先是慢速蛮力攻击(黑色):
first the slow bruteforce attack (black):
int i;
double a,da,x,y,xx,yy,ll;
a=0.0;
x=x0+rx*cos(a);
y=y0+ry*sin(a);
for (i=n;i>0;i--)
{
xx=x; yy=y;
for (da=a;;)
{
a+=0.001;
x=x0+rx*cos(a);
y=y0+ry*sin(a);
ll=sqrt(((xx-x)*(xx-x))+((yy-y)*(yy-y)));
if (ll>=l) break;
} da=a-da;
scr->MoveTo(5.0+50.0*a,5.0);
scr->LineTo(5.0+50.0*a,5.0+300.0*da);
scr->MoveTo(x0,y0);
scr->LineTo(xx,yy);
scr->LineTo(x ,y );
ll=sqrt(((xx-x)*(xx-x))+((yy-y)*(yy-y)));
scr->TextOutA(0.5*(x+xx)+20.0*cos(a),0.5*(y+yy)+20.0*sin(a),floor(ll));
}
现在近似值(蓝色):
a=0.0; da=0;
x=x0+rx*cos(a);
y=y0+ry*sin(a);
for (i=n;i>0;i--)
{
scr->MoveTo(5.0+50.0*a,5.0+300.0*da);
xx=rx*sin(a);
yy=ry*cos(a);
da=l/sqrt((xx*xx)+(yy*yy)); a+=da;
scr->LineTo(5.0+50.0*a,5.0+300.0*da);
xx=x; yy=y;
x=x0+rx*cos(a);
y=y0+ry*sin(a);
scr->MoveTo(x0,y0);
scr->LineTo(xx,yy);
scr->LineTo(x ,y );
ll=sqrt(((xx-x)*(xx-x))+((yy-y)*(yy-y)));
scr->TextOutA(0.5*(x+xx)+40.0*cos(a),0.5*(y+yy)+40.0*sin(a),floor(ll));
}
这是干净的椭圆形步骤(无调试图)
This is clean ellipse step (no debug draws)
a=???; // some initial angle
// point on ellipse
x=x0+rx*cos(a);
y=y0+ry*sin(a);
// next angle by almost constant speed
xx=rx*sin(a);
yy=ry*cos(a);
da=l/sqrt((xx*xx)+(yy*yy)); a+=da;
// next point on ellipse ...
x=x0+rx*cos(a);
y=y0+ry*sin(a);
这里是比较蛮力和逼近的输出:
Here the output of comparison bruteforce and approximation:
[edit2]精确度提高
a,da=???; // some initial angle and step (last)
x=x0+rx*cos(a);
y=y0+ry*sin(a);
// next angle by almost constant speed
xx=rx*sin(a+0.5*da); // use half step angle for aproximation ....
yy=ry*cos(a+0.5*da);
da=l/sqrt((xx*xx)+(yy*yy)); a+=da;
// next point on ellipse ...
x=x0+rx*cos(a);
y=y0+ry*sin(a);
近似的半步角导致更接近蛮力攻击的结果
the half step angle in approximation lead to much closer result to bruteforce attack
这篇关于我需要一个等式来沿着椭圆运动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!