mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
misc PVector and example cleanup
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user