【发布时间】:2017-03-11 20:30:17
【问题描述】:
我正在尝试模拟硬币的旋转。一个完整的旋转被建模为一个参数从 1 到 -1 再回到 1 的变化,1 是直硬币,-1 是倒置硬币。硬币应该逐渐减速。该函数的参数是硬币在停止前要转半圈的次数,运动应该采取的帧数,以及硬币旋转的初始速度(每帧转半圈)。
首先我用公式2*(displacement - initial_v*time) / time*time 计算减速度的值。然后我创建一个包含每帧距离值的列表。这里出了点问题,因为值真的很高。 (我省略了将位置值限制在 1 和 -1 之间的代码部分,因为在到达该点之前出现问题)。
def animate_rotation(n_half_turns, n_frames, speed):
"""
First I calculate the appropriate deceleration given distance d, initial velocity t_0, and time t
Then I find the position value per frame by calculating the distance given the found acceleration
"""
displacement = n_half_turns # every half turn is a movement from 1 to -1, i.e. 2 units
v = speed # this is the initial speed, i.e. n of half turns per frame
time = n_frames
position = 1
deceleration = 2 * (displacement - v * time) / time*time
#distance traveled from initial position for each frame
frame_distance = []
for i in range(n_frames):
position += v
frame_distance.append(position)
v += deceleration
#the rest of the code transforms the values so that they are between 1 and -1. I eliminated this part because things go wrong before it.
animate_rotation(1, 10, 1)
我希望 new_dist 列表以 n_frames 帧数(new_dist 列表的长度)中的 n_half_turns 值从一定速度开始并适当减速。然而,我在运行代码时得到的更像是一个寓言:首先位置增加,然后超出 n_half_turns,然后又回到它。 new_dist 列表为:
[1, 1.8200000000000003, 2.4600000000000004, 2.9200000000000004, 3.2, 3.3000000000000007, 3.2200000000000006, 2.960000000000001, 2.520000000000001, 1.9000000000000012]
【问题讨论】:
-
你错过了正确的缩进,还有How to Ask
-
对不起,我是新来的网站。我应该如何更改问题的主体以符合如何提问?我之前阅读了该页面,我认为我的问题符合指南。我也不确定如何增加代码块的缩进。
-
问题在于大量的解释和代码。最好能提供minimal reproducible example
-
我修改了它,希望它更符合标准。感谢当地海关的帮助!
-
在没有阅读的情况下回复了反对票和赞成票,只是为了减少和收听 cmets 的努力。现在居然发现了一个可疑的东西!!
标签: python rotation psychopy acceleration