notes_COSqueues

Count important note this is high school physics so

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: } private void predict(Particle a) add to PQ all particle-wall and particleparticle collisions involving this particle { if (a == null) return; for (int i = 0; i < N; i++) { double dt = a.timeToHit(particles[i]); pq.insert(new Event(t + dt, a, particles[i])); } pq.insert(new Event(t + a.timeToHitVerticalWall() , a, null)); pq.insert(new Event(t + a.timeToHitHorizontalWall(), null, a)); private class Event implements Comparable<Event> { private double time; // time of event private Particle a, b; // particles involved in event private int countA, countB; // collision counts for a and b public Event(double t, Particle a, Particle b) { } create event public int compareTo(Event that) { return this.time - that.time; ordered by time } } invalid if intervening collision public boolean isValid() { } private void redraw() {} public void simulate() { } /* see next slide */ } } 53 Collision system implementation: main event-driven simulation loop public void simulate() { pq = new MinPQ<Event>(); for(int i = 0; i < N; i++) predict(particles[i]); pq.insert(new Event(0, null, null)); while(!pq.isEmpty()) { Event event = pq.delMin(); if(!event.isValid()) continue; Particle a = event.a; Particle b = event.b; predict(a); predict(b); null null null null && && && && b b b b != == != == null) null) null) null) Particle collision simulation example 1 % java CollisionSystem 100 initialize PQ with collision events and redraw event get next event for(int i = 0; i < N; i++) particles[i].move(event.time - t); t = event.time; if (a != else if (a != else if (a == else if (a == 54 a.bounceOff(b); a.bounceOffVerticalWall() b.bounceOffHorizontalWall(); redraw(); update positions and time process event predict new events based on changes } } 55 56 Particle collision simulation example 2 Particle collision simulation example 3 % java CollisionSystem < billiards.txt % java CollisionSystem < brownian.txt 57 Particle collision simulation example 4 % java CollisionSystem < diffusion.txt 59 58...
View Full Document

Ask a homework question - tutors are online