Re: Bouncing circles, simple
- From: Mike Austin <noone@xxxxxxxxxxx>
- Date: Sun, 02 Oct 2005 19:26:48 GMT
cr88192 wrote:
"Mike Austin" <noone@xxxxxxxxxxx> wrote in messagerelative_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?
note: the issue is not what x+y is, but what sqrt(x*x+y*y) is.
yes, that is vector length.
now, of course, if your speed is (0.707, 0.707), well, the velocity is 1.
yep.
now, if both circles have a speed of 1 (or more) after the collision, then you have a problem.
I may have missed it earlier, but it does not look like you are handling your velocities correctly. you want to apply relative accelerations, not the absolute velocities.
The incident angle works perfectly, and actually looks great right now. But at 45d, ball1 should transfer half it's momentum to stationary ball2. cos( incident_angle - velocity_angle ) is maybe not quite right. I've tried cos(angle)^2 which gives me the correct .5, but I think I'm just hacking now. :)
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.
ok.
now, unrelated, for my uses, I have come up with a container format.
the container format is barely even classifiable as a format though, as, by itself, it is not possible to make a general purpose reader. about the only real use specifying it serves is to attempt to allow "general purpose" extension mechanisms (or as an attempt to fulfill fantasies that I am actually using a container format...). probably good enough though (it is similar to formats I have used before).
.
- References:
- Re: Bouncing circles, simple
- From: Mike Austin
- Re: Bouncing circles, simple
- From: cr88192
- Re: Bouncing circles, simple
- Prev by Date: Re: Bouncing circles, simple
- Next by Date: Re: Bouncing circles, simple
- Previous by thread: Re: Bouncing circles, simple
- Next by thread: Re: Bouncing circles, simple
- Index(es):
Relevant Pages
|