Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java 2d physics
#9
DeadHead Wrote:There's probably a better way to do the projections without having to solve for (o)comp, but its way too late/early right now to figure it out.

Basically what I did for that is that if you split the original V into 2 components (in the direction of the collision and other), subtract the (o)vel from the original, then you get the component in the other direction.



I thought about subtracting the average and you're right it's not helpful.
1 option (to make solving easier) would be subtract the speed of the 1st point from both:
ovel = ovel - vel;
vel = 0;
This makes the equations simpler since all the input motion is done by 1 sphere. If it was perfectly inelastic that leads to fv = (om/(m+om))*ovel; if it is perfectly elastic fv = 2*(om/(m+om))*ovel; fov = ((om-m)/(m+om))*ovel;
Compromise these (for partially elastic) would be something like that, for a constant a: fv = (1+a)*(om/(m+om))*ovel; fov = ((om-a*m)/(m+om))*ovel;
With a = 0.0 it is inelastic, with a = 1.0 it is elastic.
Then shift the frame of reference back by adding vel to both.

However the original velocities already have vel & ovel in them, so add the negative of that to get the velocity to add to the original to get the new one. Same thing as taking V - vel = perpendicular speed.

So
fv = (1+a)*(om/(m+om))*(ovel-vel) + (vel - vel); // 0
fov = ((om-a*m)/(m+om))*(ovel-vel) + vel - ovel;
x += dx*fv;
y += dy*fv;

Thanks for the help.


As for the rotation thing, maybe I'll skip it. In the long run most of the sphere collisions will be with non-moving surfaces (I am intending to add those next, after which I will add collisions to them)

I think I can do it in a sort of sequence, using a few numbers
1) radius of circle
2) "radius" of line (maximum distance from center)
3) centres of both

a) find the total distance between the centers
b) if distance > radius1+radius2, they don't collide
c) if distance^2 > radius1^2+radius2^2, they may collide at an end point (check if end points are touching circle)
d) if distance is shorter, the circle may be tangent - check perpendicular distance to line

In any case since all the colliding lines will be fixed (for now anyway) it makes working stuff out much easier.

Haven't had a chance to code since I'm busy with homework+study but maybe on Wednesday-Thursday I'll do something Tongue


edit: Fixed circle collisions, added initial part of line collisions (hitting the ends of a line)
[Image: springmotion13rm0.png]
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)