dcsimg
A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 57

Thread: [Resolved] [Resolved] REQUEST: Billiard balls phisics...

Hybrid View

  1. #1
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756

    Billiard balls physics

    thanx..

    MS

  2. #2
    I don't have a finished Billiard game but if you check the collusion of two balls by their distance (hit if distance <2*radius of two balls), use some of the stuff here:
    http://board.flashkit.com/board/show...hreadid=279907

    And use vectors for the speed of the balls and the speed they give to other balls when they hit them, you could do a pretty good billiard game.

    But maybe someone has the source of a finished game, would be easier

  3. #3
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Yes Don I spoted this one..the problem is that the bounce off is not that simple. I think there was a formula which calculates bounce agnle depending from the agle at which the balls touch plus there was some momentum preservation, elastic collision in 2D .complicated..

    mad

  4. #4
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    I was just playing with some bouncy balls there (very educational, right up there with slinkys). They appear to swap momentum, so the slow one goes fast and the fast one goes slow. The ball collision equation: R = 2W - P seems to work well enough. But, of course I'm sure this isn't true to nature.

  5. #5
    Senior Member
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    336
    Hey Mad-Sci,

    You might wanna have a look at:

    http://www.playpool.com/apapp/

    Dunno if this it's any help, but there seem to be some formula's there...

  6. #6
    Senior Member ironmallet's Avatar
    Join Date
    Feb 2001
    Posts
    252
    The real trick is going to be interpolating the positions of the balls to find out when they would have contacted had they not skipped past the moment of collision. Momentum won't be a huge deal since all the balls are of equal mass. So mass cancels. So total x velocity just before coll=total x velocity after coll. Just before and just after because It'll need friction, which can be faked at any desired level of complexity. I like just multiplying the x and y velocities by .9 or .8 or something.

    [swf width="100" height="100" background="#ffffff"]http://www.ironmallet.com/flashkit/Pool.swf[/swf]pool.swf

    you really have to zoom in to see that these two balls are never 2r apart, they go from >2r to <2r in one frame. I worked on this about 2 months ago, I'll look for my notes because now that there's a Math and Physics forum...

  7. #7
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    jobe makar give an excellent excellent discussion of this whole topic in flash super samurai.

  8. #8
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    I was playing pool last night, and decided to watch the balls a little more closely....It does look very difficult.

    Simply doing accurate and fast hittesting is enough of a headache.

    Still, I'm going to have a go. Probably best to start off with a good hittest, and a basic bounce, then work out rebound angles and momentum afterward.

    Then there's spin, which REALLY messes things up.

    I imagine that a good pool game in flash would require some convincing pseudophsics, rather than using any of newton's equations etc.

    I've just put this together in flash, it looks neat, but it's useless at the moment, as the balls don't collide, I'll post again as soon as I've got some kind of hittest/rebound thing going on.

    http://www.proanimate.com/pool1.swf

    Use enter to accelerate the balls, if you want to play around with it, here's the source:

    http://www.proanimate.com/pool1.fla


  9. #9
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    I saw an example where when two balls hit they swapped angles and speeds.

  10. #10
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    Just found this, a working example in flash:

    http://absolutist.com/online/pool/

    Interestingly, you can adjust the accuracy of the physics if the game runs too slow, and the lag is only noticable when balls collide.

    I'm still figuring it out.......

  11. #11
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    it's definitely not just a matter of swapping speeds or reversing directions. it is all covered in conservation of momentum. you have to know the mass, angle and speed of each ball, then determine the angle of collision (angle between the two balls at point of impact) and figure out how much of each ball's momentum lies along this line. then figure out how much momentum each ball transfers to the other, figure out the resulting momentums along that line, then translate back to world coordinates. again, jobe makar describes it very very well in super samurai. almost to the point where it is understandable for us mortals.

  12. #12
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    OK, I have not posted much on here, but I am an undergraduate engineer, and I just studied collisions in physics, so I may be of some help.

    All collisions are is a transfer of "momentum". People misuse words everyday, so momentum can be defined as
    p = m * v
    where p is momentum, m is the mass, and v is the velocity.
    V(velocity) is a vector quantity which means not only does it have a magnitude (number), but it also has a direction. This means the p (I will refer to momentum as p for the rest of this post) also must have a magnitude and direction.

    Now onto collisions. There are two types of collisions: inelastic, and elastic. In an inelastic collision, the two objects stick completely together. In an elastic collision, the two objects do not. Elastic collisions are obviously the type between two billiard balls.

    It is a fundamental law that in an elastic collision (which is also one with no outside forces), linear momentum is conserved. This means that the momentum before the collision must be equal to the momentum after the collision. Now onto some fundamental equations. These are the equations for a two object elastic collision where
    m1=mass of object 1|m2=mass of object 2|v1=velocity of ball 1|we are assume right now that object 2 is stationary.

    final velocity of ball 1= ((m1-m2)/(m1+m2))*v1
    final velocity of ball 2= ((2*m1)/(m1+m2))*v1

    Looking at these equations, one can see that if the two objects are of equal mass, then the final velocity of ball 1 will be "0" where the final velocity of ball 2 will be the initial velocity of the first ball.
    You may be thinking to yourself, "But I have played pool before, and the cue ball still have a small velocity on it after hitting another ball." This is because of two reasons. The first is simply that the cue ball is actually a fraction bigger than all of the other balls. This mostly helps commercial ball returns. If you look at the equations, you will see that the final velocity for object 1 if it is just a little bigger than object 2 will be very small. Lastly, the collision is not completely elastic. No collision will ever be completely elastic because the balls bend in a little on contact. You can't see it, but they do, and that absorbs a tad of the momentum.

    Now, what if the second ball is also moving? This is where it gets difficult. If the balls are rolling together, do you have to use one equation: m1*v1 + m2*v2 = (m1+m2)V
    But if they aren't, you have to use a different equation. What I would do is to think of the balls hitting like this: During the split second that the balls are actually touching, think of one ball as being stationary and being hit by the other ball. Then when you find the final velocity of that, just add it to the actual initial velocity. On top of that, you will need to find the components of the velocities and add them up seperate. For example, a ball that is moving at 10 m/s at an angle of 40 degrees from the horizontal has a x-velocity of 10*cos40, and a y-velocity of 10*sin40. That is about the best I can do with two balls moving at once.

    The angles that they hit is important too. The final angle that they rebound at is equal to the angle that they actually hit. You can find this angle by doing the following:
    arctan(y/x) which is the inverse tangent function of the change in y divided by the change in x. Example, if you have a ball that's center is at the point (0,0), and it is hitting another ball whose center is at (3,1), first you would find the change in X and Y. the change in Y would be (1-0)=1, and the change in X would be (3-1)=2. So the angle between the two would be the arctan(1/2), which happens to be about 26.6 degrees. Now when these two balls hit, ingoring velocities and concentrating on angles, you can see that the ball being hit will go off at an angle of 26.6 degrees, while the first ball doing the hitting will go off in the exact opposite direction, which is either
    -26.6 degrees, or 333.4 degrees.
    I won't go over it, it will take too long, and this is already a quite long post, but combining those last two methods, the first of finding the magnitudes, and the second of finding the direction, you should be able to make some pretty realistic collions. Obviously, you will want to apply a friction constant, otherwise the balls will go on forever and never stop.
    Also, there is one other collision, and that is with the ball and the rails. Obviously, most people know that it just kinda changes directions. If the ball is traveling upwards, and hits the right rail, the yvelocity will remain exactly the same, and the xvelocity will just inverse, for example initially a ball has xvel=2, and yvel=5, when it hits the rail, it will have a yvel=5, and a xvel=-2. To be more realistic you can add an effect that takes the velocity down just a tad when it does hit. But that must be quite small.
    Well, that is about all I have time for right now. I hope this helps someone, I tried to put thought and time into it. Enjoy people

  13. #13
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Can somebody please comment my pool example:
    http://www.hot.ee/tonypa/flash/flas/pool2b.html

    Its not finished, must be restarted, when cue ball goes into hole

  14. #14
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    Minger

    Thanks. That's priceless, and I haven't seen it explained so well before.

    Tonypa

    I do like that, although it's a little slow, and the action could be smoother.

    It's a damn site further than I've got, though....

  15. #15
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    Hey, it's no problem. I am just trying to help out a little with anything that I can. I ask for help with all the scripting and syntax crap, so the least I can do is help out with the things that I am good at: math and physics.

    So, like I said, I am an undergraduate engineering student, so I will try to help as much as I can with these types of questions.

  16. #16
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    here it is in action:
    http://www.bit-101.com/content/020402.swf
    http://www.bit-101.com/flafiles/020402.fla

    this throws in gravity, lift, and different sizes/masses on 10 balls just for fun.

    the fla is not commented, so here is the theory.
    calculates distance between two balls (pythag. theorem)
    if distance<sum of radii, then you have a hit.
    calculates angle between two balls.
    uses that angle to perform coordinate rotation on the x and y velocities of each ball.
    then uses the exact momentum equations given by minger to resolve the collision and new velocities.
    in my own twist on things, i manually move the balls so they are just touching each other, not intersecting. this is not mathematically correct, but keeps them from getting "stuck". this is the biggest problem with these types of collisions and various methods have been made to handle it. this is my take on it.
    then, re-rotate the velocities and carry on.

    funny, i'm now secong guessing myself if i did the rotational vectors correctly. seemed to make sense last night, but now the math seems strange. still, it looks correct.

  17. #17
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    Looks sweet Bit. Everything looks good, and the code looks good too. Man, you need to know that you are my hero. I check your page everyday to see if something new is up.
    Hope my little collision explaination helped.

    Keep up the good work.

  18. #18
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    yeah, i just worked it out again on paper and re-convinced myself that my rotations were correct. this stuff is slippery!
    actually, i used super samurai as my main learning material, but it contains all the same equations as you gave there. for someone like me who never had any formal math training, it's good to read as many versions and explanations as possible. sometimes one will give you a slightly different viewpoint that makes the whole subject click.

  19. #19
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    Yeah, anytime. If anyone needs to know anything math/physics wise, I'm the guy. Recently we learned about fluid pressure, oscillations, and now we are on waves. So, if anyone has any question about those, I might now be able to do the script, but I can give the real life equations and stuff like that.

  20. #20
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    here's another example
    http://www.bit-101.com/content/020403.swf
    http://www.bit-101.com/flafiles/020403.fla

    this one adds in large body gravity and drag & throw capabilities. looks pretty solid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center