public void setMagnitudeVelocity(double m) { Vect vel = pos.sub(oldPos); vel.setLength(m); this.oldPos = pos.sub(vel); }
public void CheckColl(Ball a) //Checking for Circle Collisions { double db = a.pos.findDistanceBetweenSq(this.pos); double er = a.rad + this.rad; if (db < er * er) { if (db == 0) { db = 1; } double m1m2 = a.mass + this.mass; Vect d = a.pos.sub(this.pos); d.setLength(er - Math.Sqrt(db)); a.pos = a.pos.add(d.mult((this.mass / m1m2))); } }
public void CheckColl(List <Ball> a) { foreach (Ball x in a) { if (x != this) { double db = x.pos.findDistanceBetweenSq(this.pos); //distance between double er = x.rad + this.rad; if (db < er * er) { double m1m2 = x.mass + this.mass; Vect d = x.pos.sub(this.pos); d.setLength(er - Math.Sqrt(db)); x.pos = x.pos.add(d.mult((this.mass / m1m2))); this.pos = this.pos.sub(d.mult((x.mass / m1m2))); } } } }