改变移动物体的方向......(纯物理问题)
这是一个纯粹的物理问题,但我不知道为什么它不起作用......我有一个移动的物体。我得到了 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());
}
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());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有 box2d 来试验,但我假设它能正常工作。
你不能忽视物体的质量;质量越大,力的作用越小。
您对 X 和 Y 的计算似乎是正确的(尽管过于复杂)。您可以通过施加到质心的冲量来改变运动::
如果您确实想使用力而不是冲量,那么有一系列解决方案。一般可以先选择力的大小,再计算方向,反之亦然。我可以给你方程(也许还有代码),但如果不了解基本物理,它就没有任何意义。
编辑:
好吧,一维运动方程是
x = x0 + V0t + at2/2,因此 WLOG 假设 ax = 1目标点的方向,并求解时间(球的 x 等于目标点的 x 的时间)。然后将时间代入 y 方程并求解 ay,就完成了。
I do not have box2d to experiment with, but I will assume it works as it should.
You cannot disregard the mass of the object; the greater the mass, the less the effect of a force.
Your calculation of X and Y seems correct (although overcomplicated). You can change the motion with an impulse applied to the center of mass::
If you really want to use a force and not an impulse, there is a range of solutions. Generally you can choose the magnitude of the force first, then calculate the direction, or the other way around. I can give you the equations (and maybe code) but it will not make any sense without an understanding of basic physics.
EDIT:
All right, the equation of one-dimensional motion is
x = x0 + V0t + at2/2, so WLOG assume ax = 1 in the direction of the target point, and solve for time (the time when the x of the ball will equal the x of the target point). Then put that time into the equation for y and solve for ay, and you're done.