Skip to content

Commit

Permalink
Fixes Issue nature-of-code#83 : variable naming in Collision Equal Mass
Browse files Browse the repository at this point in the history
  • Loading branch information
arastogi1997 committed Jul 23, 2017
1 parent 4a0873c commit 12199e6
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions chp05_physicslibraries/CollisionsEqualMass/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Mover {

Mover(PVector v, PVector l) {
vel = v.get();
loc = l.get();
pos = l.get();
}

// Main method to operate object
Expand Down Expand Up @@ -56,29 +56,29 @@ class Mover {
fill(175,200);
ellipse(pos.x,pos.y,r*2,r*2);
if (showVectors) {
drawVector(vel,loc,10);
drawVector(vel,pos,10);
}
}

void collideEqualMass(Mover other) {
float d = PVector.dist(loc,other.loc);
float d = PVector.dist(pos,other.pos);
float sumR = r + other.r;
// Are they colliding?
if (!colliding && d < sumR) {
// Yes, make new velocities!
// Yes, make new veposities!
colliding = true;
// Direction of one object another
PVector n = PVector.sub(other.loc,loc);
PVector n = PVector.sub(other.pos,pos);
n.normalize();

// Difference of velocities so that we think of one object as stationary
// Difference of veposities so that we think of one object as stationary
PVector u = PVector.sub(vel,other.vel);

// Separate out components -- one in direction of normal
PVector un = componentVector(u,n);
// Other component
u.sub(un);
// These are the new velocities plus the velocity of the object we consider as stastionary
// These are the new veposities plus the veposity of the object we consider as stastionary
vel = PVector.add(u,other.vel);
other.vel = PVector.add(un,other.vel);
}
Expand All @@ -95,6 +95,4 @@ PVector componentVector (PVector vector, PVector directionVector) {
directionVector.normalize();
directionVector.mult(vector.dot(directionVector));
return directionVector;
}


}

0 comments on commit 12199e6

Please sign in to comment.