Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Poll(ball to ball collision) physics. Help!
#11
part for you but then it occurred to me that you might already have that. I'll get to it when I can if you still need it. But it probably won't be for a few days. The same goes for modifying the routine for the case in which the balls stick together. That's not particularly difficult. (It should simplify things, actually.) But I won't have as much access to a computer for a few days as I normally have.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#12
Try the good old OLDX, OLDY hack. ;*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#13
Oh... THIS ball to ball collision.... *whew*, you were giving me a mental stroke...
Reply
#14
That really bad metaphor was worthy of *ME*.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#15
As I was pretty much sure of, if the two balls stick together after the collision, the problem's really trivial. You shouldn't even need to worry about where on the balls' surfaces the collision occurs at as far as the velocity vector of the joined balls is concerned. I'd write a subroutine for you, but I thought it might be simpler to just give you the equations. If you still need a subroutine, let me know.

Let (v1x, v1y) and m1 be the velocity vector and mass, respectively, of ball 1 before the collision, (v2x, v2y) and m2 be the velocity vector and mass, respectively, of ball 2 before the collision, and (vx, vy) be the velocity vector of the joined balls after the collision. Simply apply conservation of momentum:

m1 * v1x + m2 * v2x = (m1 + m2) * vx

and

m1 * v1y + m2 * v2y = (m1 + m2) * vy.

Hence,

vx = (m1 * v1x + m2 * v2x) / (m1 +m2)

and

vy = (m1 * v1y + m2 * v2y) / (m1 + m2).


If you still need to solve for the collision geometry, let me know.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#16
I don't know in what way this helps me. What do you mean joined balls speeds?

Khm...The subroutine would be very helpfull.

And my balls can move up to 5 pixels per loop so there's the problem. Still I think I've solved it this weekend. Not sure but I'm unable to cause ball stick effect anymore with the last alterations I've made on the code.
Reply
#17
I read "Balls when collide stick one on another" and thought that you had the situation in which you *wanted* the balls to stick together after the collision. Upon rereading, it appears that you were just describing a problem with your program. Sorry about that.

I'm working on the geometry routine.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#18
'
' Consider two circular objects moving with velocity vectors (V1X,V1Y)
' and (V2X,V2Y). At time = 0, their centers are at (X10,Y10) and
' (X20,Y20). This function calculates the "collision geometry." It
' returns directly the clockwise angle (radians, measured from the x-axis)
' about the center of the second circle the point on the perimeter of the
' two circles at which they meet. TCOL is output via the parameter list.
' It is the time at which the two circles collide. Before using the
' result returned via ANGLE, check the value of TCOL. If it is negative,
' the indication is that a collision was not possible, either because they
' are on parallel paths too far apart for a collision to occur or because
' they are moving away from each other.
'
' If you want to know where the circle centers are at TCOL:
'
' X1 = X10 + V1X * TCOL,
'
' Y1 = Y10 + V1Y * TCOL,
'
' X2 = X20 + V2X * TCOL,
'
' and
'
' Y2 = Y20 + V2Y * TCOL.
'
' Once having those, if you want to know the coordinates of the actual
' point of collision (where the two circles touch), it's
'
' XC = X2 + A2 * COS(ANGLE)
'
' and
'
' YC = Y2 + A2 * SIN(ANGLE).
'
' Your main routine needs the following DECLARE statement.
'
' DECLARE FUNCTION ANGLE(X10,Y10,X20,Y20,V1X,V1Y,V2X,V2Y,A1,A2,TCOL)
'
DEFSNG A-Z
FUNCTION ANGLE(X10,Y10,X20,Y20,V1X,V1Y,V2X,V2Y,A1,A2,TCOL)
PI=4*ATN(1)
'
' Define dummy angle and collision time in case there is no collision.
'
TEMPANGLE=0.
TCOL=-1.
'
' Get coefficients in quadratic equation.
'
A=(V1X-V2X)^2+(V1Y-V2Y)^2
B=2*((X10-X20)*(V1X-V2X)+(Y10-Y20)*(V1Y-V2Y))
C=(X10-X20)^2+(Y10-Y20)^2-(A1+A2)^2
'
' Get expression under "quadratic radical" and test it to make sure
' collision can actually occur, or did occur, before trying to solve for
' collision time.
'
Q=B^2-4*A*C
IF Q>=0 THEN
'
' Q isn't negative. Collision is physically possible. Get two times at
' which balls are just touching.
'
IF A<>0 THEN
T1=(SQR(Q)-B)/2/A : T2=-(B+SQR(Q))/2/A
'
' If neither T1 nor T2 is positive (or zero), there is no collision after
' the balls were at (X10,Y10) and (X20,Y20). If only one of them is non-
' negative, *that's* the one that means something. If they're both non-
' negative, use the minimum of the two.
'
IF T1>=0 OR T2>=0 THEN
IF T1>=0 AND T2>=0 THEN
TCOL=T1
IF T2<T1 THEN TCOL=T2
ELSEIF T1>=0 THEN
TCOL=T1
ELSE
TCOL=T2
END IF
END IF
ELSE
IF B<>0 THEN TCOL=-C/B
END IF
END IF
IF TCOL>=0 THEN
'
' Okay, get angle on circle 2 at which collision occurs. Circles will be
' at (X1,Y1) and (X2,Y2).
'
X1=X10+V1X*TCOL : Y1=Y10+V1Y*TCOL : X2=X20+V2X*TCOL : Y2=Y20+V2Y*TCOL
TEMPANGLE=(PI/2)*SGN(Y1-Y2)
IF X1<>X2 THEN TEMPANGLE=ATN((Y1-Y2)/(X1-X2))
IF X1<X2 THEN TEMPANGLE=TEMPANGLE+PI
END IF
ANGLE=TEMPANGLE
END FUNCTION
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#19
None of the suggestions consider the balls can also turn.In this case the points of impact have a tangential speed so spin communicates partly to the ball being hit. Then, spin combined with table friction can bend the ball path.
If you neglect this part in billiard you will never play as a professional....
Antoni
Reply
#20
actually thinks they're going to become a pool shark by playing on the computer in the first place? Smile
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)