用于模拟由于摩擦和重力而导致的旋转球体减速的公式的简单代码示例?

发布于 2024-09-27 13:21:53 字数 331 浏览 6 评论 0原文

我有一个旋转球体,用户可以通过施加虚拟力来旋转它,就像虚拟加速器一样。我希望能够模拟良好的动量效果,以便当它们离开加速器时,球会以自然且真实的方式降低速度,就好像由于摩擦和/或重力一样。我不想陷入任何深奥的物理方程。我想快速完成此操作,因此如果我能找到一个显示如何执行此操作的代码示例,或者甚至是一页足够清晰的公式以便我可以编码,那就太好了。

我想要一个具有一两个可调节系数的公式,我可以根据我的需要调整这些系数以使球减速得更快或更慢。我不想涉及任何繁重的事情,比如开源物理库之类的。只是一些简单的事情。

我使用的是 Delphi 6 Pro,但我也了解 C/C++、Basic、Java 和 Javascript。

I have a rotating sphere that the user rotates by applying a virtual force, like a virtual accelerator. I want to be able to simulate a nice momentum effect so that when they lift off the accelerator the ball winds down in speed in a natural and realistic way, as if due to friction and/or gravity. I don't want to get into any deep physics equations. I'd like to do this quick so if I could find a code sample that shows how to do this, or even a page of formulas clear enough that I could encode, that would be great.

I'd like a formula that has one or two adjustable coefficients that I could tune to make the ball decelerate faster or slower depending on my needs. I don't want to get into anything heavy like an open source physics library or the like. Just something simple.

I'm using Delphi 6 Pro but I also know C/C++, Basic, Java, and Javascript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

握住我的手 2024-10-04 13:21:54

速度是位移的变化。加速度是速度的变化。

重力或摩擦力只会引起加速度(可能为负)。

因此,您所需要做的就是在他们不激活加速器时应用负加速度。

因此,让我们假设您的角度正在变化。应用加速器会增加每次迭代或时间步的角度变化量。如果您的角度为 t 并且角度的变化称为 dt(角速度),那么当应用加速器时,您将得到:

t = t + dt
dt = dt + a

其中a取决于您施加的的大小,或者他们“按下”加速器的程度(即这是加速度)。

您可能想要限制 dt(即旋转速度) - 如果您只想沿一个方向旋转,您将有一个正上限和 0 下限。如果您想要两个方向,您可以有一个下限负极限和正上限。

您需要做的就是在未应用加速器时将 a 设为负数(如果 dt 为正数 - 如果 dt 为正数,则将 a 设为正数负数),并确保不“换行”(即当 dt 接近 0 时使 dt 为 0)。

Velocity is change in displacement. Acceleration is change in velocity.

Gravity or friction just causes an acceleration (possibly negative).

So all you need to do is apply a negative acceleration when they do not activate the accelerator.

So lets assume you have an angle that is changing. Applying the accelerator increases the amount the angle changes by each iteration or time step. If your angle is t and your change in angle is called dt (angular velocity) then when the accelerator is applied you'll have:

t = t + dt
dt = dt + a

where a depends on how much force you're applying, or how much they've 'pressed' the accelerator (i.e. this is the acceleration).

You'll probably want to limit dt (i.e. speed of rotation) - if you only want to spin in one direction you'll have an upper positive limit and a lower limit of 0. If you want both directions, you can have a lower negative limit and an upper positive limit.

All you need to do is make a some negative number when the accelerator is not applied (if dt is positive - make a positive if dt is negative), and ensure you don't 'wrap' (i.e. make dt 0 when it gets near 0).

梦里梦着梦中梦 2024-10-04 13:21:54

已经有一段时间了,但根据我的动力学研究书籍,球体的质量惯性矩定义为 I=(2/5)m*r^2。 m 是质量,r 是球体半径(均为 SI 单位)。在此页面上,您会找到一些示例使用质量惯性矩来计算由于施加负扭矩而导致的球体减速度。该扭矩是摩擦力的结果。由于您没有定义球体表面和周围环境的材料,因此您无法计算摩擦力,并且必须自己选择一个好的力。

It has been some time ago, but according to my dynamics study books the Mass Moment of Inertia for a sphere is defined as I=(2/5)m*r^2. m is the mass, r is the radius of the sphere (all in SI untis). On this page you'll find some examples to use the mass moment of inertia to calculate deceleration of the sphere as a result of the applied negative torque. This toqrue is a result of the friction. Since you are not defining the material of the surface of the sphere and the surroudings you cannot calculate the friction and will have to choose a good force yourself.

冷情妓 2024-10-04 13:21:54

只要你不解决恒星问题,我就不明白重力与减速旋转有何关系。

摩擦力几乎与当前旋转速度(实际上是球体表面的速度)成正比。

因此,当前转速随时间 w(t) 变化的公式可能是这样的:

w(t) = w0*exp(-c*(t - t0))

t0 是摩擦开始的时间,wt 是当时的转速。
系数c>1。 0 决定速度下降的速度 - c 越高,速度下降的越快。该公式对于所有 t >= t0 都有效。

请注意,对于 t = t0,exp 函数返回 1 并且您将获得初始速度,而对于 t -> ∞ exp 函数(以及由此产生的速度)返回 -> 0(c 前面的减号保证了这一点)。

As long as you are not solving stellar problems, I don't see how gravity has much to do with decelerating the rotation.

Friction is almost proportional to the current rotation speed (actually the speed on the surface of the sphere).

So a formula for the current rotation speed over time w(t) may be something like this:

w(t) = w0*exp(-c*(t - t0))

with t0 being the time the friction starts, wt being the rotation speed at that time.
The coefficient c > 0 determines how fast the speed will decrease - the higher c, the faster the speed will go down. This formula is valid for all t >= t0.

Note that for t = t0 the exp function returns 1 and you get the initial speed, while for t -> ∞ the exp function (and so the resulting speed) returns -> 0 (the minus in front of the c guarantees this).

无人问我粥可暖 2024-10-04 13:21:54

您已经接受了答案,但我会添加我的作品。

我假设您已经知道如何使球体以恒定速率旋转,以及如何使其在施加的扭矩下加速。让它减速只是施加另一个扭矩的问题,这个扭矩必须计算出来。

当物体在固体表面上滑动时,减速度是恒定的。力的方向与运动相反,其大小取决于多种因素,但不是速度。当物体完全停止时,力消失。这同样适用于在实心枢轴上转动的地球仪。

当物体通过流体时,减速力随速度增加而增加,因此物体速度越快,阻力越大。当物体减速时,减速会变弱,并且物体会持续减速但永远不会停止。这描述了一个在空气或水中旋转的地球仪。在相当高的速度下,阻力与 v2 成正比,在非常低的速度下,阻力与 v 成正比(我不知道这些域之间的过渡)。

所以我建议t = -a wb,其中w是角速度。参数a是摩擦力的强度,b描述了减速的类型; b=0 就像固体枢轴上的摩擦力,b=2 就像在空气中旋转,b=1 就像在糖浆中旋转。 b 的其他值可能看起来很现实,也可能不现实,或者现实的。

You've already accepted an answer, but I'll put in my piece.

I'll assume you already know how to make the sphere spin at a constant rate, and how to make it accelerate under the applied torque. Making it decellerate is just a matter of applying another torque, one that must be calculated.

When an object slides on a solid surface, the rate of deceleration is constant. The force is in the direction opposite to motion, and its magnitude depends on a couple of things but not speed. When the object comes to a full stop, the force vanishes. The same applies to a globe turning on a solid pivot.

When an object passes through a fluid, the force of decelleration increases with speed, so the faster the object the greater the drag. As the object slows down, decelleration grows weaker, and the object keeps slowing down but never stops. This describes a globe spinning in air or water. At reasonably high speeds, drag is proporional to v2, and at very low speeds it is proportional to v (I don't know about the transition between these domains).

So I suggest t = -a wb, where w is angular velocity. The parameter a is the strength of the friction, and b describes the kind of decelleration; b=0 is like friction on a solid pivot, b=2 is like spinning in air, and b=1 is like rotating in syrup. Other values of b may or may not look realistic or be realistic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文