course_planning:computation:scratch_work

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
course_planning:computation:scratch_work [2016/03/12 23:01] – [Project 2: Part C] obsniukmcourse_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,0,0) 
-  
 #Objects #Objects
-cliff = box(pos=vector(-100,0,0), size=(200,800,0), color=color.white) +hovercraft = sphere(pos=vector(-200,400,0), radius=1)
-ravine = box(pos=vector(245,-200, 0), size=(490,400,0), color=color.white) +
-lake = box(pos=vector(940, -200, 0), size=(900,400,0), material=materials.wood, color=color.blue) +
-runawaycraft = sphere(pos=vector(-200,400,0), radius=10, color=color.red) +
-rescuecraft = sphere(pos=vector(-200,400,0), radius=10, color=color.green)+
  
 #Parameters and Initial Conditions #Parameters and Initial Conditions
 g = vector(0,-9.81,0) g = vector(0,-9.81,0)
-b = 0.5  #Drag coefficient 
  
-runawaycraftm = 1500 +hovercraftm = 1500 
-runawaycraftv = vector(53.64,0,0) +hovercraftv = vector(53.64,0,0) 
-runawaycraftp = runawaycraftm*runawaycraftv +hovercraftp = runawaycraftm*runawaycraftv
- +
-rescuecraftm = 1900 +
-rescuecraftv = vector(116.366,0,0) +
-rescuecraftp = rescuecraftm*rescuecraftv +
-rescuecrafta = vector(0.2093,0,0) +
-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
  
 #MotionMap/Graph #MotionMap/Graph
-runawaycraftMotionMap = MotionMap(runawaycraft, tf, 5, markerScale=1, labelMarkerOrder=False, markerColor=color.orange) +hovercraftMotionMap = MotionMap(hovercraft, tf, 5)
-rescuecraftMotionMap = MotionMap(rescuecraft, tf, 5, markerScale=1, labelMarkerOrder=False, markerColor=color.orange)+
  
 #Calculation Loop #Calculation Loop
-while runawaycraft.pos.x < 0: +while hovercraft.pos.x < 0: 
- rate(500)+    Fgrav = hovercraftm*g 
 +    Fground = -Fgrav 
 +    Fnet = Fgrav + Fground
  
- Fgrav runawaycraftm*g +    hovercraftp hovercraftp + Fnet*dt 
- Fground -Fgrav +    hovercraft.pos hovercraft.pos + (hovercraftp/hovercraftm)*dt
- Fair = -b*dot(runawaycraftp/runawaycraftm,runawaycraftp/runawaycraftm)*runawaycraftp/mag(runawaycraftp) +
- 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)+    = t + dt 
 +</code>
  
-t + dt+<WRAP tip> 
 +== Tutor Questions == 
 +  * **Question:**  What assumptions did you make about the motion of the hovercrafts? 
 +  * **Expected Answer:**  That the runaway craft has a constant velocity, and the rescue craft starts from rest with a constant acceleration.
  
-while runawaycraft.pos.y > 0+  * **Question:**  Are these velocities and accelerations calculated from the numbers given exact? 
- rate(500)+  * **Expected Answer:**  No, these are only average numbers, not instantaneous.  In order to get more "exact" numbers, we would need more data.
  
- Fgrav = runawaycraftm*+  * **Question:**  Is the predicted position of the rescue craft a good one? 
- Fair = -b*dot(runawaycraftp/runawaycraftm,runawaycraftp/runawaycraftm)*runawaycraftp/mag(runawaycraftp) +  **Expected Answer:**  Not really, basing the trajectory off the first 20 seconds of data is probably not the best -- but it is all we have to work with.
- Fnet = Fgrav +Fair +
-  +
- runawaycraftp = runawaycraftp + Fnet*dt +
- runawaycraft.pos = runawaycraft.pos + (runawaycraftp/runawaycraftm)*dt+
  
- runawaycraftMotionMap.update(trunawaycraftp/runawaycraftm)+  * **Questions:**  Can you draw a plot of position vstime for both crafts?  What are the important features of this graph? 
 +  * **Expected Answer:**  The point where the two curves cross is when we should jump.  One should be linearthe other quadratic.
  
- t = t + dt +  * **Questions:**  Can you draw a plot of velocity vstime for both crafts?  What are the important features of this graph? 
- +  * **Expected Answer:**  The acceleration is the slope of each curve (constant in both cases). 
-while rescuecraft.pos.x < 0: +</WRAP>
- rate(500) +
- +
- Fgrav = rescuecraftm*+
- Fground = -Fgrav +
- Fair = -b*dot(rescuecraftp/rescuecraftm,rescuecraftp/rescuecraftm)*rescuecraftp/mag(rescuecraftp) +
- Fnet = Fgrav + Fground + rescuecraftF + Fair +
-  +
- rescuecraftp = rescuecraftp + Fnet*dt +
- rescuecraft.pos = rescuecraft.pos + (rescuecraftp/rescuecraftm)*dt +
- +
- rescuecraftMotionMap.update(t, rescuecraftp/rescuecraftm) +
- +
- t = t + dt +
- +
-while rescuecraft.pos.y > 0: +
- rate(500) +
- +
- Fgrav = rescuecraftm*+
- Fair = -b*dot(rescuecraftp/rescuecraftm,rescuecraftp/rescuecraftm)*rescuecraftp/mag(rescuecraftp) +
- Fnet = Fgrav + Fair +
-  +
- rescuecraftp = rescuecraftp + Fnet*dt +
- rescuecraft.pos = rescuecraft.pos + (rescuecraftp/rescuecraftm)*dt +
- +
- rescuecraftMotionMap.update(t, rescuecraftp/rescuecraftm) +
- +
- t = t + dt +
-</code>+
  • course_planning/computation/scratch_work.1457823678.txt.gz
  • Last modified: 2016/03/12 23:01
  • by obsniukm