Re: Bouncing circles, simple



cr88192 wrote:
"Mike Austin" <noone@xxxxxxxxxxx> wrote in message
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?



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).
.



Relevant Pages

  • Re: generate all possible math expr of one term
    ... The result lisp expression should match ... (+ X (TAN Y)) ... (+ X (COS Y)) ... (+ X (SIN Y)) ...
    (comp.lang.lisp)
  • Re: sin x / x tends to 1...
    ... that it's easy to show that the circumference of the unit circle ... >sin x, that we can call psin x, the limit is obvious. ... smallest positive zero of cos. ... I into the first quadrant, and that c is 1-1 on I. ...
    (sci.math)
  • Re: Mixed Coordinate conversion - ra from long and dec
    ... function of celestial longitude and declination. ... sin l cos b = cos e sin a cos d + sin e sin d ...
    (sci.astro.amateur)
  • Re: help with trig manipulation?
    ... On Mon, 12 Apr 2010, John Nagelson wrote: ... trig manipulation. ... (sin c cos x - cos c sin x) ...
    (sci.math)
  • Re: opponents of taylor and lhospital ?
    ... Suppose a high school senior taking the AP Calculus exam ... There are other ways to show that d/dx= cos x, ... computing the limit of (sin x)/x first. ... BUT practically all Calculus textbooks derive the limit of sin/x ...
    (sci.math)