create account

有多无聊:弹性碰撞与Python代码 by oflyhigh

View this thread on: hive.blogpeakd.comecency.com
· @oflyhigh ·
$17.66
有多无聊:弹性碰撞与Python代码
看到一个博主讲了一件很有意思的事情,大意是两个方块物体在水平方向上弹性碰撞后,其中一块再撞到墙壁反弹,最终会发现,在一定条件下发生弹性碰撞的次数会和PI这个常量极度相关。

![](https://cdn.steemitimages.com/DQmQgbGt8yjCTtZ3fieB8zZ2mkzaDo24V1XdFL8XcUnS8Be/image.png)
(图源 :[pixabay](https://pixabay.com/))

# 撞击次数与圆周率

为了说明这个问题,我大致画了个图(原谅我的绘图技能):
>![](https://cdn.steemitimages.com/DQmb6je2M8UVJbaHKVhHYXBNaZgaUMahAKre6wPqjrTL32q/image.png)

在上图中,有红色方块A(1)和绿色方块B(2),A以速度v1前进,B静止不动(速度v2=0),A撞击到B,B被撞后获取一定的速度vb,方块B撞击墙体(黄实线)后返回,又撞击A。

如果A、B质量相等,那么撞击会发生3次,如果A的质量大于B,撞击会发生很多次。

而这个博主总结的规律为:
>如果A、B质量相等,撞击3次
>如果A的质量是B的100倍,那么撞击31次
>如果A的质量是B的10000倍,那么撞击314次
>如果A的质量是B的1000000倍,那么撞击3141次
>如果A的质量是B的100000000倍,那么撞击31415次

观察撞击次数就会发现,撞击的次数竟然符合圆周率(PI)的规律。

# 弹性碰撞

其实如果是真实地实验,很难重现上述规律,为何?因为方块和平面之间存在摩擦,方块在空气中也会有空气阻力,方块和方块撞击时可能会发生一定程度的形变等等。

所以只有在理想情况下,才可能重现上述规律。那么什么是理想情况呢?就是不存在摩擦、不存在空气阻力、方块撞击时无形变等等。

百度百科里关于[弹性碰撞](https://baike.baidu.com/item/弹性碰撞/2321173)定义的更科学一些,直接搬来:
>在理想情况下,物体碰撞后,形变能够恢复,不发热、发声,没有动能损失,这种碰撞称为弹性碰撞(elastic collision),又称完全弹性碰撞(Perfect Elastic Collision)。

弹性碰撞符合两大物理定律:***动量守恒定律*** 以及***能量守恒定律***

而根据我们描述的情况,不难推导出,弹性碰撞后物体的速度:
>![](https://cdn.steemitimages.com/DQmV6b8z2sjYd59uZ5frzbYrxEdq1M99N8aRm7ED3xre73E/image.png)

因为我们目的不是推导公式,所以直接拿来用就好了。因为我们例子中碰撞是发生在直线上的核心碰撞,所以公式中的v,就是物体的初速度啦。

# Python代码

说了这么多,我是要证明弹性碰撞和圆周率的关系吗?非也!我只是好奇碰撞真的符合这个规律吗?

之前说了,理想情况下,实验才能重现出响应的规律,但是实际上没法弄出理想的实验条件呀?不过没关系,可以用程序模拟啊!

为了计算碰撞次数,我们首先需要计算碰撞前后的速度(其实就是简单地套用公式):
```
def collision(m1, v1, m2, v2):
        va = (v1*(m1 - m2) + 2*m2*v2)/(m1 + m2)
        vb = (v2*(m2 - m1) + 2*m1*v1)/(m2 + m1)
        return va, vb
```

接下来是计算碰撞次数,这可难住了我,如何计算碰撞次数呢?其实就是找出***符合什么条件会退出碰撞***?

从方块图中,我们不难分析出,只有当方块A向左侧行走,且方块B追不上它时,碰撞才会结束,假设向右运动为正,那么亦即符合如下条件:
>***`v1 < 0 and v2<=0 and abs(v1) >= abs(v2)`***

还有就是方块和墙壁撞击,墙壁的质量,那么代入速度公式中,不难算出:
>***`v2 = -1*v2`***

根据上述分析我写出如下代码来计算次数:
```
def func_times(m1, v1, m2, v2):
        times = 0
        while(True):
                if(v1 < 0 and v2<=0 and abs(v1) >= abs(v2)):
                        break
                v1, v2 = collision(m1, v1, m2, v2)
                times = times +1

                if(v1 < 0 and v2<=0 and abs(v1) >= abs(v2)):
                        break

                v2 = -1*v2
                times = times +1

        return times
```

# 见证奇迹

好了,现在是见证奇迹的时刻的时刻啦。
```
m1 = 100
m2 = 100
v1 = 100
v2 = 0
for i in range(0, 7):
        m1 = 100*100**i
        times = func_times(m1, v1, m2, v2)
        print(f"M1:{m1}, M2:{m2}, v1:{v1}, v2:{v2}, Times:{times}")
```

给木块设定质量和初速度,然后模拟碰撞,看看是不是符合这个博主说的规律?

运行上述程序,输出如下:
>![](https://cdn.steemitimages.com/DQmP3pK4KKwqi4SdCMBsnQvVeeQcyBR6t9A2LgTdscVRnU3/image.png)

哇哇哇,果然是圆周率啊,是不是很神奇?

![](https://cdn.steemitimages.com/DQmVhbrSPeaSgRdAUZB6B9FvxA2Rvpfnc6Ky26NAhy3avFu/image.png)
(图源 :[pixabay](https://pixabay.com/))

至于为何是圆周率,就留给聪明的你去证明啦!

# 相关链接

* [弹性碰撞](https://baike.baidu.com/item/弹性碰撞/2321173)

----
<center><strong>Vote For Me As Witness</strong>
https://steemit.com/~witnesses type in **`oflyhigh`** and click ***`VOTE`***
[![](https://cdn.steemitimages.com/DQmX5NysqT44FBa3bhuWqQ69nAbseu8Nt5YQPn2pYejPVxA/image.png)](https://steemit.com/~witnesses)
[Vote @oflyhigh via Steemconnect](https://steemconnect.com/sign/account-witness-vote?witness=oflyhigh&approve=1)
<strong>Thank you!</strong></center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 386 others
👎  
properties (23)
authoroflyhigh
permlink4qhpev-python
categorycn
json_metadata{"tags":["cn","stem","cn-stem","collision","pi"],"image":["https://cdn.steemitimages.com/DQmQgbGt8yjCTtZ3fieB8zZ2mkzaDo24V1XdFL8XcUnS8Be/image.png","https://cdn.steemitimages.com/DQmb6je2M8UVJbaHKVhHYXBNaZgaUMahAKre6wPqjrTL32q/image.png","https://cdn.steemitimages.com/DQmV6b8z2sjYd59uZ5frzbYrxEdq1M99N8aRm7ED3xre73E/image.png","https://cdn.steemitimages.com/DQmP3pK4KKwqi4SdCMBsnQvVeeQcyBR6t9A2LgTdscVRnU3/image.png","https://cdn.steemitimages.com/DQmVhbrSPeaSgRdAUZB6B9FvxA2Rvpfnc6Ky26NAhy3avFu/image.png","https://cdn.steemitimages.com/DQmX5NysqT44FBa3bhuWqQ69nAbseu8Nt5YQPn2pYejPVxA/image.png"],"links":["https://pixabay.com/","https://baike.baidu.com/item/弹性碰撞/2321173","https://steemit.com/~witnesses","https://steemconnect.com/sign/account-witness-vote?witness=oflyhigh&approve=1"],"app":"steemit/0.1","format":"markdown"}
created2019-10-16 01:19:30
last_update2019-10-16 01:19:30
depth0
children3
last_payout2019-10-23 01:19:30
cashout_time1969-12-31 23:59:59
total_payout_value9.152 HBD
curator_payout_value8.512 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,211
author_reputation6,276,672,115,522,469
root_title有多无聊:弹性碰撞与Python代码
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,595,628
net_rshares56,558,775,495,950
author_curate_reward""
vote details (451)
@dailychina ·
$0.04
!thumbup
  恭喜你!您的这篇文章入选 @justyy 今日 (2019-10-17) 榜单 [【优秀的文章】](https://steemit.com/cn/@justyy/--daily-cn-updates-cncnpower-downyy2019-10-17), 回复本条评论24小时内领赏,点赞本评论将支持 @dailychina 并增加将来您的奖赏。
 @justyy 是CN区的见证人,[请支持他,给他投票](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=justyy),或者设置justyy为[见证人代理](https://v2.steemconnect.com/sign/account-witness-proxy?proxy=justyy&approve=1)。感谢!@justyy的主要贡献:https://steemyy.com

Congratulations! This post has been selected by @justyy as today's (2019-10-17)  [【Good Posts】](https://steemit.com/cn/@justyy/--daily-cn-updates-cncnpower-downyy2019-10-17), Steem On!  Reply to this message in 24 hours to get rewards. Upvote this comment to support the @dailychina and increase your future rewards! ^_^

[SteemIt 工具、API接口、机器人和教程](https://steemyy.com/steemit-tools/)
[SteemIt Tools, Bots, APIs and Tutorial](https://SteemYY.com)<hr>
If you believe what I am doing, please consider a spare vote voting me [here](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=justyy), thank you very much indeed.

@justyy - the author of https://SteemYY.com and I have been a Steem Witness for [more than a year now.](https://steemit.com/witness-category/@justyy/one-year-winessversary-a-great-start)
👍  , , , , , , , , , , , ,
properties (23)
authordailychina
permlinkre-4qhpev-python-20191017t080127
categorycn
json_metadata""
created2019-10-17 08:01:27
last_update2019-10-17 08:01:27
depth1
children0
last_payout2019-10-24 08:01:27
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.021 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,249
author_reputation50,124,640,567,504
root_title有多无聊:弹性碰撞与Python代码
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,634,997
net_rshares252,737,199,372
author_curate_reward""
vote details (13)
@partiko ·
Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.22% upvote! Together, let’s change the world!
properties (22)
authorpartiko
permlinkre-4qhpev-python-20191016t023014
categorycn
json_metadata"{"app": "partiko"}"
created2019-10-16 02:30:15
last_update2019-10-16 02:30:15
depth1
children0
last_payout2019-10-23 02:30:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length213
author_reputation39,207,160,334,751
root_title有多无聊:弹性碰撞与Python代码
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,596,684
net_rshares0
@steemstem ·
re-oflyhigh-4qhpev-python-20191017t123405983z
<div class='text-justify'> <div class='pull-left'> <center> <br /> <img width='200' src='https://res.cloudinary.com/drrz8xekm/image/upload/v1553698283/weenlqbrqvvczjy6dayw.jpg'> </center>  <br/> </div> 

This post has been voted on by the **SteemSTEM curation team** and voting trail. It is elligible for support from @curie and @minnowbooster.<br /> 

If you appreciate the work we are doing, then consider supporting our witness [@stem.witness](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=stem.witness). Additional witness support to the [curie witness](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=curie) would be appreciated as well.<br /> 

For additional information please join us on the [SteemSTEM discord]( https://discord.gg/BPARaqn) and to get to know the rest of the community!<br />

Please consider using the <a href='https://www.steemstem.io'>steemstem.io</a> app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.
properties (22)
authorsteemstem
permlinkre-oflyhigh-4qhpev-python-20191017t123405983z
categorycn
json_metadata{"app":"steemstem-bot"}
created2019-10-17 12:34:09
last_update2019-10-17 12:34:09
depth1
children0
last_payout2019-10-24 12:34:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,050
author_reputation262,017,435,115,313
root_title有多无聊:弹性碰撞与Python代码
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,641,148
net_rshares0