public void collide(Bubble other) { Point otherpos = other.getPosition(); double otherrad = other.getRadius(); double distancesquared = (otherpos.x - position.x) * (otherpos.x - position.x) + (otherpos.y - position.y) * (otherpos.y - position.y); double radiussquared = (otherrad + radius) * (otherrad + radius); if (distancesquared < radiussquared) { double magnitude = (1 - (distancesquared * distancesquared) / (radiussquared * radiussquared)) * pushStrength; double pushangle = Math.Atan((otherpos.y - position.y) / (otherpos.x - position.x)) + Math.PI; if (otherpos.x < position.x) pushangle += Math.PI; velocity.x += magnitude * Math.Cos(pushangle); velocity.y += magnitude * Math.Sin(pushangle); } }
public static bool containsPoint(Bubble bubble, Point point) { Bubble.Point bubblepos = bubble.getPosition(); return (bubblepos.x - point.X) * (bubblepos.x - point.X) + (bubblepos.y - point.Y) * (bubblepos.y - point.Y) < bubble.getRadius() * bubble.getRadius(); }