Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
course_planning:computation:scratch_work [2016/03/12 23:01] – [Project 2: Part C] obsniukm | course_planning:computation:scratch_work [2016/03/25 18:40] (current) – [Code] obsniukm | ||
---|---|---|---|
Line 29: | Line 29: | ||
<code python> | <code python> | ||
- | from __future__ import division | ||
- | from visual import * | ||
- | from physutil import * | ||
- | |||
- | #Window setup | ||
- | scene.width = 1024 | ||
- | scene.height = 768 | ||
- | scene.center = vector(600, | ||
- | |||
#Objects | #Objects | ||
- | cliff = box(pos=vector(-100, | + | hovercraft |
- | ravine = box(pos=vector(245, | + | |
- | lake = box(pos=vector(940, | + | |
- | runawaycraft | + | |
- | rescuecraft = sphere(pos=vector(-200, | + | |
#Parameters and Initial Conditions | #Parameters and Initial Conditions | ||
g = vector(0, | g = vector(0, | ||
- | b = 0.5 #Drag coefficient | ||
- | runawaycraftm | + | hovercraftm |
- | runawaycraftv | + | hovercraftv |
- | runawaycraftp | + | hovercraftp |
- | + | ||
- | rescuecraftm = 1900 | + | |
- | rescuecraftv = vector(116.366, | + | |
- | rescuecraftp = rescuecraftm*rescuecraftv | + | |
- | rescuecrafta = vector(0.2093, | + | |
- | rescuecraftF = rescuecraftm*rescuecrafta | + | |
#Time and time step | #Time and time step | ||
t=0 | t=0 | ||
- | tf=5 | + | tf=10 |
dt = 0.01 | dt = 0.01 | ||
# | # | ||
- | runawaycraftMotionMap | + | hovercraftMotionMap |
- | rescuecraftMotionMap = MotionMap(rescuecraft, | + | |
# | # | ||
- | while runawaycraft.pos.x < 0: | + | while hovercraft.pos.x < 0: |
- | rate(500) | + | Fgrav = hovercraftm*g |
+ | Fground = -Fgrav | ||
+ | Fnet = Fgrav + Fground | ||
- | Fgrav | + | hovercraftp |
- | Fground | + | |
- | Fair = -b*dot(runawaycraftp/runawaycraftm, | + | |
- | Fnet = Fgrav + Fground + Fair | + | |
- | runawaycraftp = runawaycraftp + Fnet*dt | + | hovercraftMotionMap.update(t, hovercraftp/hovercraftm) |
- | runawaycraft.pos = runawaycraft.pos + (runawaycraftp/runawaycraftm)*dt | + | |
- | runawaycraftMotionMap.update(t, runawaycraftp/runawaycraftm) | + | |
+ | </code> | ||
- | t = t + dt | + | <WRAP tip> |
+ | == Tutor Questions == | ||
+ | * **Question: | ||
+ | * **Expected Answer: | ||
- | while runawaycraft.pos.y > 0: | + | * **Question:** Are these velocities and accelerations calculated from the numbers given exact? |
- | rate(500) | + | * **Expected Answer: |
- | Fgrav = runawaycraftm*g | + | |
- | Fair = -b*dot(runawaycraftp/ | + | * **Expected Answer: |
- | Fnet = Fgrav +Fair | + | |
- | + | ||
- | runawaycraftp = runawaycraftp + Fnet*dt | + | |
- | runawaycraft.pos = runawaycraft.pos + (runawaycraftp/ | + | |
- | runawaycraftMotionMap.update(t, runawaycraftp/ | + | * **Questions: |
+ | * **Expected Answer: | ||
- | t = t + dt | + | |
- | + | * **Expected Answer:** The acceleration is the slope of each curve (constant in both cases). | |
- | while rescuecraft.pos.x < 0: | + | </WRAP> |
- | rate(500) | + | |
- | + | ||
- | Fgrav = rescuecraftm*g | + | |
- | Fground = -Fgrav | + | |
- | Fair = -b*dot(rescuecraftp/ | + | |
- | Fnet = Fgrav + Fground + rescuecraftF + Fair | + | |
- | + | ||
- | rescuecraftp = rescuecraftp + Fnet*dt | + | |
- | rescuecraft.pos = rescuecraft.pos + (rescuecraftp/ | + | |
- | + | ||
- | rescuecraftMotionMap.update(t, rescuecraftp/ | + | |
- | + | ||
- | t = t + dt | + | |
- | + | ||
- | while rescuecraft.pos.y > 0: | + | |
- | rate(500) | + | |
- | + | ||
- | Fgrav = rescuecraftm*g | + | |
- | Fair = -b*dot(rescuecraftp/ | + | |
- | Fnet = Fgrav + Fair | + | |
- | + | ||
- | rescuecraftp = rescuecraftp + Fnet*dt | + | |
- | rescuecraft.pos = rescuecraft.pos + (rescuecraftp/ | + | |
- | + | ||
- | rescuecraftMotionMap.update(t, rescuecraftp/ | + | |
- | + | ||
- | t = t + dt | + | |
- | </code> | + |