Qbasicnews.com
April 05, 2020, 04:41:32 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: Poll(ball to ball collision) physics. Help!  (Read 4350 times)
Lachie Dazdarian
I hold this place together
*****
Posts: 955



WWW
« Reply #15 on: June 30, 2003, 06:14:01 AM »

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.
Logged
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #16 on: June 30, 2003, 12:05:26 PM »

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

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.
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #17 on: June 30, 2003, 01:34:02 PM »

'
'  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
Logged

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.
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #18 on: June 30, 2003, 05:27:00 PM »

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

Antoni
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #19 on: June 30, 2003, 06:07:53 PM »

actually thinks they're going to become a pool shark by playing on the computer in the first place?  Smiley
Logged

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.
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #20 on: June 30, 2003, 06:14:12 PM »

Just nitpicking...  Cheesy

I once asked a question about texturemapping a sphere to display
Earth spinning in Screen 13 and someone said I should take into account the Earth is not  a sphere... :rotfl:
Logged

Antoni
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #21 on: June 30, 2003, 06:41:22 PM »

what about height?

when i play pool, half the balls go in because they jump up and in.

The other half just fall to the floor.  :lol:
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #22 on: June 30, 2003, 07:37:35 PM »

do you think I was doing?  (I'd be a lousy nitpicker if I didn't recognize it.)  You don't seriously think that I think that you think that people here think they can learn to play pool without a pool table, do you?  Smiley  (Read that last sentence 5 times fast.)

Agamemnus, maybe *you* shouldn't do it with a real table.  Smiley  (However, skilled pool players will sometimes actually make the cue ball jump over balls in their way.  I'll let *you* write that program.)
Logged

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.
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!