notes_COSqueues

j public void movedouble dt public void draw jx

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ouble dvdv = dvx*dvx + dvy*dvy; double drdr = dx*dx + dy*dy; double sigma = this.radius + that.radius; double d = (dvdr*dvdr) - dvdv * (drdr - sigma*sigma); if (d < 0) return INFINITY; return -(dvdr + Math.sqrt(d)) / dvdv; } 50 Collision system: event-driven simulation main loop two particles on a collision course Initialization. ・Fill PQ with all potential particle-wall collisions. ・Fill PQ with all potential particle-particle collisions. no collision third particle interferes: no collision “potential” since collision may not happen if some other collision intervenes An invalidated event public void bounceOff(Particle that) { double dx = that.rx - this.rx, dy = that.ry - this.ry; double dvx = that.vx - this.vx, dvy = that.vy - this.vy; double dvdr = dx*dvx + dy*dvy; double dist = this.radius + that.radius; double J = 2 * this.mass * that.mass * dvdr / ((this.mass + that.mass) * dist); double Jx = J * dx / dist; double Jy = J * dy / dist; this.vx += Jx / this.mass; this.vy += Jy / this.mass; that.vx -= Jx / that.mass; that.vy -= Jy / that.mass; this.count++; Important note: This is high-school physics, so we won’t be testing you on it! that.count++; } Main loop. ・Delete the impending event from PQ (min priority = t). ・If the event has been invalidated, ignore it. ・Advance all particles to time t, on a straight-line trajectory. ・Update the velocities of the colliding particle(s). ・Predict future particle-wall and particle-particle collisions involving the colliding particle(s) and insert events onto PQ. 51 52 Event data type Collision system implementation: skeleton Conventions. ・ ・One particle null ・Both particles null public class CollisionSystem { private MinPQ<Event> pq; private double t = 0.0; private Particle particles; Neither particle null ⇒ particle-particle collision. ⇒ particle-wall collision. ⇒ redraw event. // the priority queue // simulation clock time // the array of particles public CollisionSystem(Particle particles) {...
View Full Document

Ask a homework question - tutors are online