输入将来自stdin
下面是一个输入示例
20 1 0 0 0 0 0 1 one
2 5 0 1 100 0 0 0 two
表明:
球1的质量是20,半径是1。它的初始位置是(0,0,0)和初始值
速度是(0,0,1)
球2的质量是2,半径是5。其初始位置为(0,1100)和初始位置
速度是(0,0,0)
当程序遇到文件结束符(EOF或ctrl-D)时,它意味着所有
物体已经进入,模拟应该开始了。
球的数量可以是0,1,2,或更多(没有限制)。
程序运行时必须有两个命令行参数,像这样:
python spheres.py 120 14.5
这意味着容器半径是120米,结束
模拟时间为14.5秒
所有质量、半径、位置都可以是任意浮点数。
碰撞极限是一个正整数。
程序开始时提示开始场景:
Please enter the mass, radius, x/y/z position, x/y/z velocity
and name of each sphere
When complete, use EOF / Ctrl-D to stop entering
程序一旦知道了初始条件,就会首先输出
初始情况,包括容器半径,最大碰撞,和
每个球的状态。 (universe’s radius, the max collisions, and the
status of each sphere.)
然后报告
•每次碰撞(球体对球体)
•每个反射(球体到容器)
在每次碰撞或反射后,报告所有球的情况,包括
新速度。
当没有更多的事件时,程序应该退出并返回代码0。
每个浮点数都应该使用:g格式说明符来打印,如
f"{x:g}"
输入输出示例
从三个方面考虑这个场景时输入为:
20 1 0 0 0 0 0 1 one
2 5 0 1 100 0 0 0 two
3 1 2 -1 -2 0 0 0 three
执行python spheres.py 120 105 的输出为
Here are the initial conditions.
universe radius 120.0
end simulation 105
one m=20 R=1 p=(0,0,0) v=(0,0,1)
two m=2 R=5 p=(0,1,100) v=(0,0,0)
three m=3 R=1 p=(2,-1,-2) v=(0,0,0)
energy: 10
momentum: (0,0,20)
Here are the events.
time of event: 94.0839
colliding one two
one m=20 R=1 p=(0,0,94.0839) v=(0,-0.0298792,0.823232)
two m=2 R=5 p=(0,1,100) v=(0,0.298792,1.76768)
three m=3 R=1 p=(2,-1,-2) v=(0,0,0)
energy: 10
momentum: (0,0,20)
time of event: 102.539
reflecting two
one m=20 R=1 p=(0,-0.252632,101.044) v=(0,-0.0298792,0.823232)
two m=2 R=5 p=(0,3.52632,114.946) v=(0,0.189874,-1.78267)
three m=3 R=1 p=(2,-1,-2) v=(0,0,0)
energy: 10
momentum: (0,-0.217836,12.8993)
请问你可以写一下你自己的思考和设计,以及碰到什么具体的问题么?