Sunday, October 24, 2010

Linear colisions

fastgraphics

m1=4 : v1=10 :p1=57
m2=20 : v2=0 : p2=150
elast=.5
font "arial",15,15
While abs(p1-150)<151 and abs(p2-150)<151
clg
Text 0,10,"Pos1= "+int(p1)
Text 130,10,"Vel1= "+v1
Text 0,40,"Pos2="+int(p2)
Text 130,40,"Vel2="+v2
circle p1,150,m1
circle p2,150,m2
refresh
p1=p1+v1
p2=p2+v2
if abs(p1-p2)<=m1+m2 then
v11=v1
v1=(elast*m2*(v2-v1)+m1*v1+m2*v2)/(m1+m2)
v2=(elast*m1*(v11-v2)+m1*v11+m2*v2)/(m1+m2)
end if
pause.05
end while

No comments:

Post a Comment