pool physics

hi there, can anybody explain the pool physics, i already understand the conservation of momentum but i got trouble on determining the velocity vector, after the collision.thanks,
[200 byte] By [synluba] at [2007-9-28 7:39:39]
# 1
and don't forget fluid dynamics. pools are full of water.
outawatera at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 2
I would recommend looking at the game Balls at http://www.geocities.com/myavuzselim/and the source at http://www.geocities.com/myavuzselim/ballssrc.zipBut I'm not sure you it would help because the code is very ugly to fit under 4 kb.
myavuzselima at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 3
ha..ha..ha, may be i would need that one too.btw i need some help here ! please anybody ! pool/billiard physics ?
synluba at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 4
thanks for the source myavuzselim,
synluba at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 5
local teacher of physics? I found alot of knowledge for this sort of thing at the local high school, and the teachers are really glad to share the info with someone who is interested vs the students that are chained to the desks.....
Exception13a at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 6
What are you planning on doing wrt spin? If you're not using spin, it's simple. Conservation of momentum and conservation of energy (since ball-ball collisions are nearly elastic) give you quadratic equations to solve.
YATArchivista at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 7
how about in 2D/3D collision, after a ball collides with another ball, how to find the right vector for these ball, after collision ?thanks,
synluba at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 8
maybe, http://www.amazon.com/exec/obidos/tg/detail/-/0596000065/qid=1042593019/sr=8-1/ref=sr_8_1/102-1327723-4402518?v=glance&s=books&n=507846
mchan0a at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 9

i already solved the momentum and energy things, but the matter is the velocity vector after collision in 2D/3D coordinate.

in pool/billiard, the mass of the balls are the same (m1=m2=m). so to get the velocity after collision is by switching the velocity.

v1a = v2b

v2a = v1b

thanks,

synluba at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 10
Look at that picture: http://www.geocities.com/myavuzselim/bilardo.htmI find it difficult to tell, so I hope it helps by looking.
myavuzselima at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 11
+ There is one more example: http://home.hkstar.com/~yyf/game1.htmlIt has cleaner source code with more comments.
myavuzselima at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 12

Hi,

I was physics major in graduate school. If you need help, please contact me. I used to write an elastic/inelastic, bound/boundless collision simulation in Java applet. If you need source code, I can try to find it and (if I can) send to you as well.

qizhi@sinotar.com

www.sinotar.com -- internet values.

sinotara at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 13

My friend and I made this a while ago. Sorry for the lack of comments, it was mostly written very quickly after scribbling on lots of pieces of paper.

It calculates a perfectly elastic collision given a position, velocity vector, and mass.

/*

the all-knowing, all-seeing, do-everything bouncing ball function

give unto me the position of your balls, their masses, and their component vectors

and I shall bestow unto you their resultant vectors in an array of doubles

by abe and john, april 5 2002

*/

double[] calculateBounce( double x1, double y1, double m1, double dx1, double dy1,

double x2, double y2, double m2, double dx2, double dy2 )

{

// calculate a bunch of things

double angle = findAngle( x2 - x1, y1 - y2 ),

b1vector = findAngle( dx1, dy1 ),

b1mag = findDist( dx1, dy1 ),

b1parl = b1mag * Math.cos( b1vector - angle ),

b1perp = b1mag * Math.sin( b1vector - angle ),

b2vector = findAngle( dx2, dy2 ),

b2mag = findDist( dx2, dy2 ),

b2parl = b2mag * Math.cos( b2vector - angle ),

b2perp = b2mag * Math.sin( b2vector - angle ),

newb1parl = collision( b1parl, m1, b2parl, m2 ),

newb1vector = findAngle( newb1parl, b1perp ) + angle,

newb1mag = findDist( newb1parl, b1perp ),

newb2parl = collision( b2parl, m2, b1parl, m1 ),

newb2vector = findAngle( newb2parl, b2perp ) + angle,

newb2mag = findDist( newb2parl, b2perp ) ;

// return an array with the resultant vectors { dx1, dy1, dx2, dy2 }

return new double[] { newb1mag * Math.cos( newb1vector ), newb1mag * Math.sin( newb1vector ),

newb2mag * Math.cos( newb2vector ), newb2mag * Math.sin( newb2vector ) } ;

}

double collision( double v1, double m1, double v2, double m2 )// linear bouncing

{

return ( m1 - m2 ) / ( m1 + m2 ) * v1 + 2 * m2 * v2 / ( m1 + m2 ) ;

}

public double findDist( double x, double y )

{

return Math.sqrt( x * x + y * y ) ;

}

public double findAngle( double x, double y )

{

if( x == 0 && y >= 0 )

return Math.PI / 2 ;

if( x == 0 && y < 0 )

return 3 * Math.PI / 2 ;

double a = Math.atan( (double) y / x ) ;

if( x < 0 )

a += Math.PI ;

return a ;

}

danperkinsa at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 14
Has anyone got source code to a pool game
qwwertya at 2007-7-9 18:53:00 > top of Java-index,Other Topics,Java Game Development...
# 15
yes I do.check my java3d pool game.let me know if you need informations http://www.geocities.com/calzada_us/Billard3D/Pool.htmlthanks for your feed back,Franck
fcalzadaa at 2007-7-18 19:30:35 > top of Java-index,Other Topics,Java Game Development...
# 16

hi,

you can check my physics if you want at

http://www.geocities.com/calzada_us/Billard3D/Pool.html

Franck

source for ballI collide ballJ

-

Ball ballI = Pool.instance().getBall(i);

Ball ballJ = Pool.instance().getBall(j);

Debug.log(

Debug.FINE, Events.class, "setBallEvent BALL_COLLIDE_BALL", "ballI={0}",

ballI

);

Debug.log(

Debug.FINE, Events.class, "setBallEvent BALL_COLLIDE_BALL", "ballJ={0}",

ballJ

);

double v1, v2, r1, r2, s = 2, t, v, apr = 1.0;

double diffX = ballI.getPosition().x - ballJ.getPosition().x;

double diffY = ballI.getPosition().y - ballJ.getPosition().y;

double diffSpeed = Math.sqrt(diffX * diffX + diffY * diffY);

diffX /= diffSpeed;

diffY /= diffSpeed;

v1 = ballI.getVitesse().x * diffX + ballI.getVitesse().y * diffY;

r1 = ballI.getVitesse().x * diffY - ballI.getVitesse().y * diffX;

v2 = ballJ.getVitesse().x * diffX + ballJ.getVitesse().y * diffY;

// impact velocity

r2 = ballJ.getVitesse().x * diffY - ballJ.getVitesse().y * diffX;

//

t = (v1 + v2) / s;

v = t + apr * (v2 - v1) / s;

ballI.getVitesse().x = v * diffX + r1 * diffY;

ballI.getVitesse().y = v * diffY - r1 * diffX;

v = t + apr * (v1 - v2) / s;

ballJ.getVitesse().x = v * diffX + r2 * diffY;

ballJ.getVitesse().y = v * diffY - r2 * diffX;

ballI.setNewAcceleration();

ballJ.setNewAcceleration();

Debug.log(

Debug.FINE, Events.class, "setBallEvent BALL_COLLIDE_BALL done", "ballI={0}",

ballI

);

Debug.log(

Debug.FINE, Events.class, "setBallEvent BALL_COLLIDE_BALL done", "ballJ={0}",

ballJ

);

if (Pool.instance().isShotting()) {

ballI.setCollideSoundEnable(true);

}

fcalzadaa at 2007-7-18 19:30:35 > top of Java-index,Other Topics,Java Game Development...
# 17
can somebody please give me 2 D pool game code in java....
farswana at 2007-7-18 19:30:35 > top of Java-index,Other Topics,Java Game Development...
# 18
> can somebody please give me 2 D pool game code in java....Why?
prometheuzza at 2007-7-18 19:30:35 > top of Java-index,Other Topics,Java Game Development...
# 19
> > can somebody please give me 2 D pool game code in> java....> > Why?you need to still ask that? The answer is well known I thought "my prof zux and I need to do this for him by monday and I don't know where to start"...
jwentinga at 2007-7-18 19:30:35 > top of Java-index,Other Topics,Java Game Development...