控制声明

发布于 2024-12-09 06:39:32 字数 185 浏览 0 评论 0原文

我需要数学逻辑问题的帮助。 假设我有一个可以由用户操纵(移动)的对象。 用户移动物体后,我希望物体继续移动并减速停止。

例如,当用户将一个物体从A点移动到B点,X轴总距离为100像素时,在用户松开手指后,我想让该物体继续移动并从B点减速到C点。

所以如果设置2秒减速停止时间,如何计算C点的新距离?

谢谢你!

I need help in a Math logic issue.
Let say I have an object that can be manipulate (move) by user.
After the user moved the object I would like the object to continue moving and decelerate to a stop.

Example, when a user move an object from point A to B with a total distance of 100pixel in X axis, after user release a finger, I want to let the object continue moving and decelerate to a stop from point B to point C.

So how can I calculate the new distance of point C if I set the time for it to decelerate and stop in 2sec?

Thank you!

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

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

发布评论

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

评论(3

柠檬色的秋千 2024-12-16 06:39:32

d = ½at² + vit + d0

d0 是用户“放手”的点。在放手之前根据运动计算 vi。将 a 设置为负值;你必须摆弄这个才能让它感觉正确。将 t 从 0 增加到 2。d 是对象最终的位置。请记住,a 和 vi 是指向相反方向的向量,d0 和 d 是

d = ½at² + vit + d0

d0 is the point at which the user "let go". Calculate vi from the motion before letting go. Set a to something negative; you'll have to fiddle with this to get it to feel right. Increment t from 0 through 2. d is where the object will end up. Remember that a and vi are vectors pointing in opposite directions, and that d0 and d are points.

无需解释 2024-12-16 06:39:32

如果加速度 a 恒定,您可以使用以下公式:

d = ½at²

当 t = 2s 时,您可以得到 d = 2a。

加速度足以在2s内加速到v,
所以 a = v/2。

可以得到:

d = v

因此,如果 v= 每秒 100 像素,则如果物体在恒定减速下 2 秒内停止,则应继续移动 100 像素。

If the acceleration, a, is constant you can use the formula:

d = ½at²

With t = 2s you get d = 2a.

The acceleration is enough to accelerate to v in 2s,
so a = v/2.

You get:

d = v

So if v= 100 pixels per second, the object should continue 100 pixels if it stops in 2 seconds under constant deceleration.

妳是的陽光 2024-12-16 06:39:32

如果您想要的只是从 BC距离,那很简单。如果对象在 k 秒内从 AB 移动了 N 个像素(例如 100),则从 B的距离C 将是 N/k。

如果您想要 C位置,以便 A、B 和 C 是 x 轴上的整数,则 C = B+(BA)/k。

如果您想要为运动设置动画,以便可以在每个时间步 dt(例如 0.1 秒)更新位置 x,则从 v= 开始(在 B 处) N/k,并且在每一步中,

x += v * dt
v -= N * dt/(2 * k)

(确保使用浮点数,而不是整数,否则舍入误差会破坏效果。)

If all you want is the distance from B to C, that's easy. If the object went a distance N pixels (say 100) from A to B in k seconds, then the distance from B to C will be N/k.

If you want the location of C, so that A, B and C are integers on the x-axis, C = B+(B-A)/k.

If you want to animate the motion, so that you can update the position x at every time step dt (say 0.1 seconds), then start (at B) with v=N/k, and at each step,

x += v * dt
v -= N * dt/(2 * k)

(Be sure to use floats, not integers, or the round-off error will ruin the effect.)

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