Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java 2d physics
#7
Got that far, but I can't seem to get the 1d collision to act realistically.

Code:
            double rate = (dx*vx + dy*vy)/(Math.pow(dx,2)+Math.pow(dy,2));
            double orate = (dx*ovx + dy*ovy)/(Math.pow(dx,2)+Math.pow(dy,2));
            // average
            double arate = (rate+orate)/2;
            // mass weighted
            double rm = m*(rate-arate);
            double orm = om*(orate-arate);
            // elasticity
            double a = 0.1;
            // new vector   other's v   avg   to balance
            double ir = a*(orm-rm)/(m)+arate - rate;
            double oir = a*(rm-orm)/(om)+arate - orate;
            vx += ir*dx;
            vy += ir*dy;
            ovx += oir*dx;
            ovy += oir*dy;
First I calculate the projection onto the vector (dx,dy) - the difference in centre - for the 2 particles (v, ov). Then subtract the average speed (I'm not sure this is done properly but I went with what works, doing this in other order led to problems) then multiply each by weight(m) to get momentum, then swap those, then find the overall change.

I think the main trouble I have is that when 2 particles are traveling the same way, with a smaller one following, it'll keep bouncing off the surface of the larger and then swinging back (due to gravity/pendulum) but I've never really tested these irl so, I don't know if that's correct.
[Image: springmotion11zd4.png]
Every frame where a collision is detected is coloured red, you can see they only make contact about every 10. In the other direction (big following small) they stay closer together, with contact every 2nd frame.


Normally looks like this, I just disable the overwriting to make the animation paths clear.
[Image: springmotion12ie7.png]




I'd also like to add rotational speed via these collisions, I think it would just be radius*angular v = surface velocity, combine that and the relative motion of the 2 to get a difference in surface speed, and use some sort of friction model to speed up/slow down the rotation speed.
Reply


Messages In This Thread
Java 2d physics - by Stereo - 2009-02-05, 10:23 PM
Java 2d physics - by Spaz - 2009-02-06, 08:31 PM
Java 2d physics - by Stereo - 2009-02-06, 11:04 PM
Java 2d physics - by Spaz - 2009-02-07, 03:13 AM
Java 2d physics - by Stereo - 2009-02-07, 01:57 PM
Java 2d physics - by DeadHead - 2009-02-08, 08:42 PM
Java 2d physics - by Stereo - 2009-02-09, 10:30 AM
Java 2d physics - by DeadHead - 2009-02-10, 03:40 AM
Java 2d physics - by Stereo - 2009-02-10, 10:25 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)