以下内容为转载内容,来自:http://tr4work.blog.163.com/blog/static/1371493142011329113733260/
不多说了,直接上算法:
b = ((y1-y3)*(x1*x1-x2*x2)-(y1-y2)*(x1*x1-x3*x3))/((x1-x3)*(x1*x1-x2*x2)-(x1-x2)*(x1*x1-x3*x3));
a = ((y1-y2)-b*(x1-x2))/(x1*x1-x2*x2);
c = y1-a*x1*x1-b*x1;
//x轴速度为vx
float vx = width/5;//5为秒
//算出新坐标
- (void)update:(ccTime)dt {
CGPoint position = sprite.position;
x = position.x + dt*vx;
y = a*x^2 + b*x + c;
sprite.position = ccp(x, y);
}
这是我用在cocos2d游戏中的一个抛物线路径算法,希望对大家有用