This site requires JavaScript, please enable it in your browser!
Greenfoot back

Comments for Rigid Body Physics Engine

Return to Rigid Body Physics Engine

A new version of this scenario was uploaded on Thu Nov 05 16:05:22 UTC 2009
A new version of this scenario was uploaded on Thu Nov 05 16:10:37 UTC 2009
MTKMTK

2009/11/5

i forgot to add the Actors! :)
A new version of this scenario was uploaded on Sat Nov 07 23:34:53 UTC 2009
MTKMTK

2009/11/7

I found some site that explained collisions a little bit, and the formula from there is used here: http://www.myphysicslab.com/collision.html But it doesn't say anything about friction, and I don't completely understand it :( Oh, and the blue ball is twice more massive then the red one, I forgot to say that in the description.
This is looking really great! The collisions seem to be working really well, and running the scenario for a long period of time doesn't seem to yield any problems :) Just out of curiosity, have you seen my Rigid Body physics engine?
MTKMTK

2009/11/8

Yes, I did see it. I am trying to figure out collisions with friction, now.
MTKMTK

2009/11/8

I created my own collision algorithm, but I have no idea how to implement rotation it it. norm = norm.unit(); PhysicsObject a = this; Vector2D ua = a.velocity; Vector2D ub = b.velocity; Vector2D uab = ua.subtract(ub); if(uab.dotProduct(norm) < 0) { double e = (a.elasticity + b.elasticity) / 2; double f = Math.min(a.friction, b.friction); Vector2D tang = norm.perpendicular(); Vector2D uaNorm = ua.projectOnto(norm); Vector2D uaTang = ua.projectOnto(tang); Vector2D ubNorm = ub.projectOnto(norm); Vector2D ubTang = ub.projectOnto(tang); Vector2D vaNorm = elasticCollision(uaNorm, a.mass, ubNorm, b.mass, e); Vector2D vbNorm = elasticCollision(ubNorm, b.mass, uaNorm, a.mass, e); Vector2D inelasticVTang = inelasticCollision(uaTang, a.mass, ubTang, b.mass); Vector2D vaTang = inelasticVTang.scale(f).add(uaTang.scale(1-f)); Vector2D vbTang = inelasticVTang.scale(f).add(ubTang.scale(1-f)); a.velocity = vaNorm.add(vaTang); b.velocity = vbNorm.add(vbTang); } I wonder if a solution would be to have a method that applies an impulse to a certain point on the body or something?
I think the impulse idea would work well. We know that since we are avoiding friction for the moment, a collision can only exert force along the normal. (And consequently with spheres, rotation does not occur) If we take into account friction, then there is a force tangential to the surface. Anyway, when you do impulse on a point, a percentage of that force goes into rotation, and the other percentage goes into translation. This is a bit more difficult for me though, since I do my simulating in a completely different matter, by simulating the elasticity and deformation of the object XD
MTKMTK

2009/11/9

For the impulse function, I guess you can find the normal velocity component and apply that to the object's linear velocity. But for the tangential component, I am not sure how to calculate how much of it will go into rotation and how much will go into translation.
MTKMTK

2009/11/9

As for now it seems to be working well with my impulse method idea, but no rotation yet...
birdguybirdguy

2009/11/24

about the incodent it is OK i have gone through this situation before
MTKMTK

2009/11/24

I don't understand what this is about and why you posted this in my scenario.
MTKMTK

2009/11/24

I don't understand what this is about and why you posted this in my scenario.
MTKMTK

2009/11/24

Oops, I accidentally clicked submit twice.