这是一个纯粹的物理问题,但我不知道为什么它不起作用....我有一个移动的物体。我得到了 vcos(theta) 和 vsin(theta) 的值...从这个我计算速度和运动角度.....我也知道另一个点(x,y)并想将物体引导到这一点。我想我需要施加一定的力(力必须具有 X 和 Y 轴值)到将物体指向该点……所以要获得所需的力,我只需遵循以下公式:
fX=V2cos(theta2)-V1cos(theta1) fY=V2sin(theta2)-V1sin(theta1)
无论下面给出什么语法(我给那些知道目标c的人)............我的等式不起作用......任何人都可以帮助......
if (acceleration.x>1.5 || acceleration.y>1.5) {
shakeCounter++;
[_label setString:[NSString stringWithFormat:@"%d",shakeCounter]];
//get the velocity of moving object.......................
b2Vec2 mVelik = ballBody->GetLinearVelocityFromLocalPoint(localPoint);
float angleOfCurrentDirectionOfMotion;
float angleOfDesiredDirectionOfMotion;
//calculate first velocity
float V1=sqrt(pow(mVelik.x, 2)+pow(mVelik.y, 2));
//calculate second velocity
float V2=V1+factor;
//calculate current angle
angleOfCurrentDirectionOfMotion=atan(mVelik.y/mVelik.x);
//calculate desired angle
angleOfDesiredDirectionOfMotion=atan(acceleration.y/acceleration.x);
///calculate FX and FY
float X=V2*cos(angleOfDesiredDirectionOfMotion)-V1*cos(angleOfCurrentDirectionOfMotion);
float Y=V2*sin(angleOfDesiredDirectionOfMotion)-V1*sin(angleOfCurrentDirectionOfMotion);
b2Vec2 force = b2Vec2(X,Y);
///apply Force to change direction....
ballBody->ApplyForce(force, ballBody->GetPosition());
}