IntroductiontoParticleSimulationsDanielPlayneParticleSimulationsAnothermajorclassofsimulationsareparticleorn-bodysimulations.Inthesesimulationsthestateofthesystemisrepresentedbyparticles.ParticleSimulationsGenerallyeachparticleisrepresentedbyasetoffields.Theseareoften:apositionavelocityamassaradiusandpossibly:arotationanangularvelocityParticleSimulationsTheseparticlescanrepresentdifferententitiesdependingonthesimulation.Thiscouldbe:atomsmoleculesdustparticlessnookerballsasteroidsplanetsgalaxiesParticleSimulationsTheseparticlesallbehaveinfundamentallysimilarways.ThisbehaviourisbasedonNewton’sLawsofMotion.Thesethreelawsarethebasisforclassicalmechanics.ParticleSimulationsFirstLaw:Everyobjectcontinuesinitsstateofrest,orofuniformmotioninastraightline,unlesscompelledtochangethatstatebyexternalforcesacteduponit.ParticleSimulationsSecondLaw:TheaccelerationaofabodyisparallelanddirectlyproportionaltothenetforceFactingonthebody,isinthedirectionofthenetforce,andisinverselypropotionaltothemassmofthebody.F=maParticleSimulationsThirdLaw:Whentwobodiesinteractbyexertingforceoneachother,theseforcesareequalinmagnitude,butoppositeindirection.ParticleSimulationsSimplecase–HockeyPucksEachparticlerepresentsahockeypuckslidingaroundontheice.Thisissimple2Dsystemisrelativelyeasytosimulate.ParticleSimulationsFirststep–Vectors.InthissenseavectorisreferringtoamathematicalorEuclideanvector.Theseconsistofco-ordinatesinspace.Weusuallytalkinvectorsbecauseitmakesiteasiertodefinesomethingin1D,2D,3D,4D...ParticleSimulationsForour2Dhockeypucksavectorisassimpleas(x,y).Weneedtwovectorsforeachparticle–positionandvelocity.Inthiscasewearegoingtoassumethateveryhockeypuckhasthesamemassandthesameradius.ParticleSimulationsInthiscaseeachparticlehasapositionpandavelocityvwithmassm=1andradiusr=1.Tosimulatetheparticlesmoving,wemustcalculateanewpositionfortheparticleaftersomeperiodoftimehaspassed.Thisisthetime-stepofthesimulation.ParticleSimulationsThiscanbewrittensimplyas:pt+h=pt+vt*hThisisknownastheEulerintegrationmethod.Whichissuitableforthistypeofparticlesimulation.ParticleSimulationsOuralgorithmtoupdateaparticlesimulationisassimpleas:•mainloop–forallparticles•‘move’particle•repeatParticleSimulationsOuralgorithmtoupdateaparticlesimulationisassimpleas:for(inti=0;iN;i++){p[i]=p[i]+v[i]*h;}ParticleSimulationsUnfortunatelythisisaratherboringsimulation.Eachparticlemovesinastraightlineandwillneverstop.Tomakeitslightlymoreinterestingwewillhavetoenforcecollisions.Collisionsoccurwhena‘hard’particlehitsintoanother‘hard’object.ParticleSimulationsTheeasiestcollisionsareparticlescollidingwithimmovableobjects.Inthiscaseourhockeypucksbouncingoffthewallsofthehockeyrink.ParticleSimulationsInanycollisionsystemtherearetwoparts,thecollisiondetectionandthecollisionresponse.Tochecktoseeifapuckhascollidedwiththesidesoftherink,simplychecktoseeifthepuckisoutsidethebounds.ParticleSimulationsOnceacollisionhasbeendetectedthesystemmustrespondtothecollision.Forourhockeypucks,simplyreversethevelocityinthedirectionofthecollision.ParticleSimulations•mainloop–forallparticles•‘move’particle•if‘collision’withboundary–respondtocollision•repeatParticleSimulationsOuralgorithmtoupdateaparticlesimulationisassimpleas:for(inti=0;iN;i++){p[i]=p[i]+v[i]*h;if(p[i].x-r0||p[i].x+rwidth){v[i].x=-v[i].x;}if(p[i].y-r0||p[i].y+rheight){v[i].y=-v[i].y;}}ParticleSimulationsMorecomplexobjectswillrequiremorecomplexcollisiondetectionandresponsesystems.Forexample–hockeypucksbouncingoffeachother.ParticleSimulationsThisisnowsignificantlymorecomplicated.Aftereachtime-stepthesimulationmustcompareeverypairofparticlestoseeiftheyhavecollidedbycalculatingthedistancebetweenthemandcheckingtoseeifthatdistanceislessthanthecombinedradiusofthehockeypucks.ParticleSimulations•mainloop–forallparticles•‘move’particle•if‘collision’withboundary–respondtocollision–forallparticles•forallotherparticles–if‘collision’betweenparticles»respondtocollision•repeatParticleSimulations...for(inti=0;iN;i++){for(intj=0;jN;j++){if(distance(p[i],p[j])r*2){collision!}}}ParticleSimulationsRespondingtoacollisionbetweenparticlesismorecomplicatedthananimmovablewall.Inourexamplethemassofbothparticlesisthesamewhichmakesthecollisioneasiertocalculate.ParticleSimulationsCalculatingacollisioninonedimensionissimpleifthemassesarethesame:v1=u2v2=u1where:u1andu2aretheinitialvelocitiesv1andv2arethefinalvelocitiesParticleSimulationsIntwodimensionsthisisnotassimple.Thevelocitiesoftheparticlesmustbesplitintothecomponentsthatareinthedirectionofthecollision.ParticleSimulationsThe‘component’ofthevelocitytobeusedinthecollisionisfoundfromthedotproductofthevelocityandtheunitvector.ParticleSimulationsThiscomponentisthepartusedinthecollision:u1d1=u1.x*d1.x+u1.y*d1.yd1d2u2u1u1*(u1d1)u2*(u2d2)ParticleSimulationsThisishowthenewvaluecanbecalculated.u1*(u1d1)u2*(u2d2)u1v1u1*(u1d1)u2*(u2d2)u2v2ParticleSimulationsu1*(u1d1)u2*(u2d2)u1v1u1*(u1d1)u2*(u2d2)u2v2ParticleSimulationsu1*(u1d1)u2*(u2d2)u1v1Thiscalculationcanbewrittenas:v1=u1–u1*(dot(u1,d1))+u2*(dot(u2,