Re: Bouncing circles, simple
- From: Mike Austin <noone@xxxxxxxxxxx>
- Date: Sat, 01 Oct 2005 17:30:31 GMT
cr88192 wrote:
"Mike Austin" <no@xxxxxxxx> wrote in message<snip>
I don't know why you're using e or what restitution is supposed to do. Here's my revised pseudo-code, but I'm not sure it conserves momentum - "object_a velocity length + object_b velocity length" should be equal before and after the collision, correct?
e is mostly just what I used before (originally I think it came from one of the papers I read). however, the notion was not new to me, just, previously, I had not bothered to come up with a good name for it anyways (it was stuck in one of my general purpose 'f' or 'g' variables).
generally, it refers to how much of a "bounce force" to add. otherwise, if all is working well, the objects should not bounce (inelastic collisions).
I am, however, not sure on whether or not the laws of conservation still hold (whenever there is a collision, a little fudging is made to the forces). reality works a little different on this front, and typically physical realism was put at a lower priority than "visual realism".
relative_position = object_a.position - object_b.position
incident_angle = atan2( relative_position.y, relative_position.x )
velocity_angle = atan2( object_a.velocity.y, object_a.velocity.x )
magnitude := object_a.velocity length * cos( incident_angle - velocity_angle )
object_a.velocity -= vector( cos( incident_angle ) * magnitude, sin( incident_angle ) * magnitude ) object_b.velocity += vector( cos( incident_angle ) * magnitude, sin( incident_angle ) * magnitude )
[calc object_b]
yeah, it might work. if one does not need mass or other features, this could be ok.
The problem still remains that it does not conserve momentum. At an incident angle of 45d, a ball moving at speed 1 that collided with a stationary ball will result in each ball having the speed .7071 (cos 45). At 45d, ball1 should transfre half it's momentum, correct?
still, worth noting:
though subtle, I still view "impulses" as an important feature.
instead of applying forces to velocity directly, they accumulate them and add them at the end of the frame.
something like: object_a.impulse -= vector( cos( incident_angle ) * magnitude, sin( incident_angle ) * magnitude ) object_b.impulse += vector( cos( incident_angle ) * magnitude, sin( incident_angle ) * magnitude )
and after all the physics are done: object.velocity += object.impulse object.impulse = vector(0, 0)
the effects of this are related to multiple contacts.
in the multiple contact case, often, one collision will prevent correctly handling another, and so forth (a simple example of this would be, in the case of multiple contacts, some contacts having little effect on an objects movement, so during that time, eg, an object will head right through another or other weird effects).
otherwise, it is not that expensive to add them.
I get it, thanks. .
- Follow-Ups:
- Re: Bouncing circles, simple
- From: cr88192
- Re: Bouncing circles, simple
- Next by Date: Analog Gamepads
- Next by thread: Re: Bouncing circles, simple
- Index(es):
Relevant Pages
|