Hi,
This is a pure physic question but i don't know why it doesn't work....i have a moving object.i get the value of vcos(theta) and vsin(theta)...from this i calculate the velocity and angle of motion.....also i know another point (x,y) and want to direct the object to this point.I think i need to apply a certain force(force must have X and Y axis value)to direct the object towards the point....so to get the amount of force required i just follow the formula:
fX=V2cos(theta2)-V1cos(theta1) fY=V2sin(theta2)-V1sin(theta1)
no matter what ever the syntex are given bellow(i give it for those people know objective c).........my equation doesn't work.....can anyone help......
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());
}