Fysik 1/Logbog uge 39
Fra Meinertz Wiki
< Fysik 1(Forskel mellem versioner)
Meinertz (diskussion | bidrag) (Siden blev oprettet: <pre> # -*- coding: utf-8 -*- from visual import * from random import gauss ball=sphere(pos=(0,0,0),radius=0.05,color=color.blue) arrowtails="atorigin" #avec=arrow(color=color...) |
Meinertz (diskussion | bidrag) m (Tilføjer kategori) |
||
| (Versionssammenligningen medtager 3 mellemliggende versioner.) | |||
| Linje 1: | Linje 1: | ||
| + | Gruppemedlemmer: | ||
| + | * Henrik Bo Hoffmann Carlsen | ||
| + | * Julius Bier Kirkegaard | ||
| + | * Jonas Meinertz Hansen | ||
| + | fra laboratoriehold theta | ||
| + | |||
| + | I dag har vi lært at bruge VPython. Vi fik forholdsvis hurtigt lavet et program, der simulerede en bold, der falder i parabel under tyngdeaccelerationen. Vi fik programmet til at tegne projektilbanen samt en vektor for impuls, der fulgte bolden. | ||
| + | |||
| + | Herefter modificerede vi eksempelfilen til at inkludere en vinkelhastighedsvektor vha. krydsproduktet. | ||
| + | |||
| + | Her er vores program (VPythonHelloWorld.py): | ||
<pre> | <pre> | ||
| - | |||
from visual import * | from visual import * | ||
| - | + | autoscale=0 | |
| + | x=5 | ||
| + | scene.range=(x,x,x) | ||
| - | + | print 'Hello World!' | |
| + | mass1=sphere(pos=(0.0,2.0,0.0),radius=0.5,color=color.red) | ||
| + | mass1.mass=0.1 | ||
| + | mass1.velocity=vector(10,0,0) | ||
| + | g=vector(0,-9.82,0) | ||
| + | a=0 | ||
| + | path=curve(radius=0.05) | ||
| + | |||
| + | retning=arrow(color=color.blue,shaftwidth=0.05) | ||
arrowtails="atorigin" | arrowtails="atorigin" | ||
| - | |||
| - | |||
| - | |||
| - | + | dt=0.01 | |
| - | + | t=0 | |
| - | + | while t<20: | |
| - | + | rate(20) | |
| - | + | mass1.velocity=g*t+mass1.velocity | |
| - | + | mass1.pos=mass1.pos+mass1.velocity*dt | |
| - | + | path.append(pos=mass1.pos) | |
| + | retning.pos=mass1.pos | ||
| + | retning.axis=mass1.velocity*mass1.mass | ||
| + | t=t+dt | ||
| + | </pre> | ||
| - | + | Og vores modificerede version af Ian Beardens program (ModifiedCircularMotion.py): | |
| - | + | ||
| - | + | <pre> | |
| - | + | from visual import * | |
| - | + | ||
| - | + | t = 0 | |
| - | + | dt=0.01 | |
| - | + | w=1.0 | |
| - | + | arrowtails="atorigin" | |
| + | scene.range=(3,3,3) | ||
| - | + | particle=sphere(radius=0.17,color=color.yellow) | |
| - | + | rvec=arrow(color=color.blue,shaftwidth=0.1) | |
| - | + | vvec=arrow(color=color.green,shaftwidth=0.1) | |
| - | + | avec=arrow(color=color.red,shaftwidth=0.11) | |
| - | + | path=curve(radius=0.04) | |
| - | + | rlabel=label(pos=(0,-1.0,0), text='position', xoffset=0, yoffset=-12, | |
| - | + | height=15, border=10,box=0) | |
| - | + | vlabel=label(pos=(0,-1.0,0), text='velocity', xoffset=0, yoffset=-42, | |
| - | + | height=15, border=10,box=0) | |
| - | + | alabel=label(pos=(0,-1.0,0), text='acceleration', xoffset=0, yoffset=-72, | |
| - | + | height=15, border=10,box=0) | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | omega=arrow(color=color.yellow,shaftwidth=0.1) | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | while t<100: | |
| + | rate(100) | ||
| + | if scene.kb.keys: | ||
| + | s=scene.kb.getkey() | ||
| + | if s=="up": w=w+0.2 | ||
| + | if s=="down": w=w-0.2 | ||
| + | if s=="left":arrowtails="atorigin" | ||
| + | if s=="right":arrowtails="onparticle" | ||
| + | if s=="p":dt=0 | ||
| + | if s=="g":dt=0.01 | ||
| + | |||
| + | r=vector(sin(w*t),cos(w*t)) | ||
| + | v=vector(w*cos(w*t),-w*sin(w*t)) | ||
| + | a=vector(-w**2*sin(w*t),-w**2*cos(w*t)) | ||
| + | particle.pos=r | ||
| + | omega.axis=cross(r,v)/mag(r)**2 | ||
| + | |||
| + | rvec.axis=r | ||
| + | vvec.axis=v | ||
| + | avec.axis=a | ||
| + | |||
| + | |||
| + | rlabel.text="r = ("+str(r.x)+") i + ("+str(r.y)+") j" | ||
| + | vlabel.text="v = ("+str(v.x)+") i + ("+str(v.y)+") j" | ||
| + | alabel.text="a = ("+str(a.x)+") i + ("+str(a.y)+") j" | ||
| + | if arrowtails=="onparticle": | ||
| + | vvec.pos=r | ||
| + | avec.pos=r | ||
| + | if arrowtails=="atorigin": | ||
| + | vvec.pos=(0,0) | ||
| + | avec.pos=(0,0) | ||
| + | path.append(pos=r) | ||
| + | t=t+dt | ||
</pre> | </pre> | ||
| + | |||
| + | Her er et billede af resultatet: | ||
| + | |||
| + | [[Billede:Fyslab uge39.jpg]] | ||
| + | [[Kategori:Fysik 1]] | ||
Nuværende version fra 8. nov 2009, 17:10
Gruppemedlemmer:
- Henrik Bo Hoffmann Carlsen
- Julius Bier Kirkegaard
- Jonas Meinertz Hansen
fra laboratoriehold theta
I dag har vi lært at bruge VPython. Vi fik forholdsvis hurtigt lavet et program, der simulerede en bold, der falder i parabel under tyngdeaccelerationen. Vi fik programmet til at tegne projektilbanen samt en vektor for impuls, der fulgte bolden.
Herefter modificerede vi eksempelfilen til at inkludere en vinkelhastighedsvektor vha. krydsproduktet.
Her er vores program (VPythonHelloWorld.py):
from visual import *
autoscale=0
x=5
scene.range=(x,x,x)
print 'Hello World!'
mass1=sphere(pos=(0.0,2.0,0.0),radius=0.5,color=color.red)
mass1.mass=0.1
mass1.velocity=vector(10,0,0)
g=vector(0,-9.82,0)
a=0
path=curve(radius=0.05)
retning=arrow(color=color.blue,shaftwidth=0.05)
arrowtails="atorigin"
dt=0.01
t=0
while t<20:
rate(20)
mass1.velocity=g*t+mass1.velocity
mass1.pos=mass1.pos+mass1.velocity*dt
path.append(pos=mass1.pos)
retning.pos=mass1.pos
retning.axis=mass1.velocity*mass1.mass
t=t+dt
Og vores modificerede version af Ian Beardens program (ModifiedCircularMotion.py):
from visual import *
t = 0
dt=0.01
w=1.0
arrowtails="atorigin"
scene.range=(3,3,3)
particle=sphere(radius=0.17,color=color.yellow)
rvec=arrow(color=color.blue,shaftwidth=0.1)
vvec=arrow(color=color.green,shaftwidth=0.1)
avec=arrow(color=color.red,shaftwidth=0.11)
path=curve(radius=0.04)
rlabel=label(pos=(0,-1.0,0), text='position', xoffset=0, yoffset=-12,
height=15, border=10,box=0)
vlabel=label(pos=(0,-1.0,0), text='velocity', xoffset=0, yoffset=-42,
height=15, border=10,box=0)
alabel=label(pos=(0,-1.0,0), text='acceleration', xoffset=0, yoffset=-72,
height=15, border=10,box=0)
omega=arrow(color=color.yellow,shaftwidth=0.1)
while t<100:
rate(100)
if scene.kb.keys:
s=scene.kb.getkey()
if s=="up": w=w+0.2
if s=="down": w=w-0.2
if s=="left":arrowtails="atorigin"
if s=="right":arrowtails="onparticle"
if s=="p":dt=0
if s=="g":dt=0.01
r=vector(sin(w*t),cos(w*t))
v=vector(w*cos(w*t),-w*sin(w*t))
a=vector(-w**2*sin(w*t),-w**2*cos(w*t))
particle.pos=r
omega.axis=cross(r,v)/mag(r)**2
rvec.axis=r
vvec.axis=v
avec.axis=a
rlabel.text="r = ("+str(r.x)+") i + ("+str(r.y)+") j"
vlabel.text="v = ("+str(v.x)+") i + ("+str(v.y)+") j"
alabel.text="a = ("+str(a.x)+") i + ("+str(a.y)+") j"
if arrowtails=="onparticle":
vvec.pos=r
avec.pos=r
if arrowtails=="atorigin":
vvec.pos=(0,0)
avec.pos=(0,0)
path.append(pos=r)
t=t+dt
Her er et billede af resultatet:
