• Welcome to Jose's Read Only Forum 2023.
 

The Ripe Tomato and the Politician: Collision Physics

Started by Charles Pegge, October 19, 2007, 02:12:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

Modelling a Simple Non-Elastic Collision

This shows the collision between two objects which fuse together resulting in a new object. By combining their momentums, we can calculate the resultant velocity. It must be said however that this model is too simple when applied to a skillful politician who would be able to deflect the tomato by spinning.




' The collision and fusion of two objects


#COMPILE EXE
#DIM ALL



TYPE physical_object
px AS DOUBLE  ' position
py AS DOUBLE
pz AS DOUBLE
vx AS DOUBLE  ' velocity
vy AS DOUBLE
vz AS DOUBLE
mass AS DOUBLE
END TYPE

SUB set_physical_object(_
ob   AS physical_object,_
px   AS DOUBLE,_
py   AS DOUBLE,_
pz   AS DOUBLE,_
vx   AS DOUBLE,_
vy   AS DOUBLE,_
vz   AS DOUBLE,_
mass AS DOUBLE _
)
ob.px=px
ob.py=py
ob.pz=pz
ob.vx=vx
ob.vy=vy
ob.vz=vz
ob.mass=mass
END SUB


SUB collide_physical_objects ( _
a AS physical_object,_
b AS physical_object,_
r AS physical_object _
)
r.mass=a.mass+b.mass

' net velocity using m*v momentum calculation
r.vx = ( a.vx*a.mass + b.vx*b.mass ) /r.mass
r.vy = ( a.vy*a.mass + b.vy*b.mass ) /r.mass
r.vz = ( a.vz*a.mass + b.vz*b.mass ) /r.mass
a.mass=0
b.mass=0
END SUB



FUNCTION PBMAIN () AS LONG

DIM politician AS physical_object
DIM tomato     AS physical_object
DIM result     AS physical_object

set_physical_object politician, 0, 0, 0, 1 , 0, 0, 100
set_physical_object tomato    , 0, 0, 0,-10, 0, 0, .10

collide_physical_objects tomato,politician,result

MSGBOX  "Velocity:"+$CR+ _
"x:    "+FORMAT$(result.vx,"00.000")+$CR+_
"y:    "+FORMAT$(result.vy,"00.000")+$CR+_
"z:    "+FORMAT$(result.vz,"00.000")+$CR+_
"mass: "+FORMAT$(result.mass,"000.000")

END FUNCTION


Kent Sarikaya

Charles funny setup of the story for this example and cool name for a physics demo, still smiling thinking about it!

Charles Pegge


I made a subtle but important change to the code above: setting the masses of our two original objects to zero. This can be used in a program to indicate that these entities no longer participate in any physical interactions. The result of the collision is a single object.

But this single object may only exist temporarily, as its two components become unstuck and disengage from each other. Hence the case of the unripe tomato as it makes contact with the noble brow of the politician and bounces off in the opposit direction.

This program shows how two objects collide together transiently forming a single body then rebounding from each other without energy loss. The rebound velocity is the exact reverse of the contact velocity as referenced from the fused body.

Another parameter has been added to the collision fusion, a flag to indicated whether the collision was elastic or not.





' The collision and fusion and eleatic rebound of two objects


#COMPILE EXE
#DIM ALL



TYPE physical_object
px AS DOUBLE  ' position
py AS DOUBLE
pz AS DOUBLE
vx AS DOUBLE  ' velocity
vy AS DOUBLE
vz AS DOUBLE
mass AS DOUBLE
END TYPE

SUB set_physical_object(_
ob   AS physical_object,_
px   AS DOUBLE,_
py   AS DOUBLE,_
pz   AS DOUBLE,_
vx   AS DOUBLE,_
vy   AS DOUBLE,_
vz   AS DOUBLE,_
mass AS DOUBLE _
)
ob.px=px
ob.py=py
ob.pz=pz
ob.vx=vx
ob.vy=vy
ob.vz=vz
ob.mass=mass
END SUB


SUB collide_physical_objects ( _
a AS physical_object,_
b AS physical_object,_
r AS physical_object, _
elast AS DOUBLE _
)
r.mass=a.mass+b.mass

' net velocity using m*v momentum calculation
r.vx = ( a.vx*a.mass + b.vx*b.mass ) /r.mass
r.vy = ( a.vy*a.mass + b.vy*b.mass ) /r.mass
r.vz = ( a.vz*a.mass + b.vz*b.mass ) /r.mass
IF elast=0 THEN
  a.mass=0
  b.mass=0
  EXIT SUB
END IF
' Elastic rebound
a.vx=r.vx-(a.vx-r.vx)
b.vx=r.vx-(b.vx-r.vx)


r.mass=0
END SUB



FUNCTION PBMAIN () AS LONG

DIM politician AS physical_object
DIM tomato     AS physical_object
DIM result     AS physical_object

set_physical_object politician, 0, 0, 0, 1 , 0, 0, 100
set_physical_object tomato    , 0, 0, 0,-10, 0, 0, .10

collide_physical_objects tomato,politician,result, 1

MSGBOX  "Elastic Collision"+$CR+_
"Fused Velocity:"+$CR+ _
"x:    "+FORMAT$(result.vx,"00.000")+$CR+_
"y:    "+FORMAT$(result.vy,"00.000")+$CR+_
"z:    "+FORMAT$(result.vz,"00.000")+$CR+_
"Tomato Velocity:"+$CR+ _
"x:    "+FORMAT$(tomato.vx,"00.000")+$CR+_
"y:    "+FORMAT$(tomato.vy,"00.000")+$CR+_
"z:    "+FORMAT$(tomato.vz,"00.000")+$CR+_
"Politician Velocity:"+$CR+ _
"x:    "+FORMAT$(politician.vx,"00.000")+$CR+_
"y:    "+FORMAT$(politician.vy,"00.000")+$CR+_
"z:    "+FORMAT$(politician.vz,"00.000")+$CR

END FUNCTION