The “Simulation Thing”“模拟物”

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

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:u1d1=u1.x*d1.x+u1.y*d1.yd1d2u2u1u1*(u1d1)u2*(u2d2)ParticleSimulationsThisishowthenewvaluecanbecalculated.u1*(u1d1)u2*(u2d2)u1v1u1*(u1d1)u2*(u2d2)u2v2ParticleSimulationsu1*(u1d1)u2*(u2d2)u1v1u1*(u1d1)u2*(u2d2)u2v2ParticleSimulationsu1*(u1d1)u2*(u2d2)u1v1Thiscalculationcanbewrittenas:v1=u1–u1*(dot(u1,d1))+u2*(dot(u2,

1 / 40
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功