回上方

第12堂課

比較有相同動量但不同質量的物體速度的快慢

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf8 -*-
# 匯入視覺化套件
from vpython import *

#  1. 參數設定
#物質密度 單位: kg/m**3
density_stucco = 400.0
density_metal = 900.0
density_earth = 2600.0
#球半徑 0.05m
size = 0.05
#地板長
L = 1.00
#時間間隔
dt = 0.001
#體積
V = (4/3)*pi*(size)**3
#初始動量 kg*m/s
P = 0.1

#  2. 畫面設定
scene = canvas(width=800, height=800, background=vector(0.5,0.6,0.5))
bottom = box(pos=vector(0,-size,0), length=2*L, height=0.001, width=2)
wall = box(pos=vector(L,-size/2,0), length=0.01, height=size, width=2)

#  3. 球的設定
ball_stucco = sphere(pos=vector(-L,0,-0.40), radius=size, texture=textures.stucco)
ball_metal = sphere(pos=vector(-L,0,0), radius=size, texture=textures.metal)
ball_earth = sphere(pos=vector(-L,0,0.40), radius=size, texture=textures.earth)

#質量
ball_stucco.m = V*density_stucco
ball_metal.m = V*density_metal
ball_earth.m = V*density_earth
#速度
ball_stucco.v = P / ball_stucco.m
ball_metal.v = P / ball_metal.m
ball_earth.v = P / ball_earth.m

#  4. 運動
while True:
    rate(1000)
    ball_stucco.pos.x = ball_stucco.pos.x + ball_stucco.v * dt
    ball_stucco.rotate(axis=vector(0,0,1), angle = -ball_stucco.v*dt/size)
    if ball_stucco.pos.x >= L-size:
        ball_stucco.v = 0

    ball_metal.pos.x = ball_metal.pos.x + ball_metal.v * dt
    ball_metal.rotate(axis=vector(0,0,1), angle = -ball_metal.v*dt/size)
    if ball_metal.pos.x >= L-size:
        ball_metal.v = 0

    ball_earth.pos.x = ball_earth.pos.x + ball_earth.v * dt
    ball_earth.rotate(axis=vector(0,0,1), angle = -ball_earth.v*dt/size)
    if ball_earth.pos.x >= L-size:
        ball_earth.v = 0

作業

請修改上述程式碼,使用串列(list)與迴圈(for loop)畫出三顆滾動的球。


本單元課程自2018.7.5日起已被瀏覽 73