misc PVector and example cleanup

This commit is contained in:
Daniel Shiffman
2013-03-18 22:12:27 -04:00
parent 0c35ad10a5
commit 9a466e1866
6 changed files with 10 additions and 21 deletions
@@ -18,10 +18,9 @@ class Sun {
PVector attract(Planet m) {
PVector force = PVector.sub(location,m.location); // Calculate direction of force
float d = force.mag(); // Distance between objects
d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
force.mult(strength); // Get force vector --> magnitude * direction
force.setMag(strength); // Get force vector --> magnitude * direction
return force;
}