NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
July 22, 2018, 10:23:36 am
 Welcome, Guest. Please login or register.Did you miss your activation email? 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length

 Home Help Search Login Register
"Nothing in life is to be feared, it is only to be understood." ..."Marie Curie 1867-1934, Polish born French Physicist, Twice Nobel Prize Winner- Physics and Chemistry)"

 Pages: 1 [2] 3   Go Down
 Author Topic: Billiards and Physics  (Read 269105 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
rajettan
Newbie

Offline

Posts: 3

 « Embed this message Reply #30 on: July 19, 2007, 12:45:08 am »

its true that we always see the past for light takes definite time to reach our eye.sunlight takes 8 minutes aprox to reach earth.that means we are seeing 8 minute old sun.can we argue in any way that we can see tha future.please help
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #31 on: July 20, 2007, 10:32:16 pm »

we are seeing 8 minute old sun. So we can see the past instead of future.
 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #32 on: December 29, 2007, 04:17:35 pm »

Dear Mr Hwang I would like to know if you have written any article on billiard physics which comes with example code. I found the applet available really helpfull unfortunately some part of it seem quite complex and I was wondering if you further explanation is available somewhere in your website.

Thanks
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #33 on: December 29, 2007, 09:08:05 pm »

I do not know what do you mean by "some part of it seem quite complex"? Which part?
Do you mean: how I processed the collision between two particles in two dimension?
If it is the case, please check out 2D Collision
You will find out how it was calculated and how the code was implemented (with source code).
 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #34 on: February 15, 2008, 08:43:38 am »

Dear Mr Hwang

I would like to understand how you approached about solving the collision problem. Did you use any sort of standard algorithm so that I go and read the right resource?

If not could you please explain to me how you solve the velocity after collision?

Thank you in advance.
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #35 on: February 15, 2008, 04:17:52 pm »

Please check 2D Collision or  Collision 2D(EJS version)
for more information. You can find out the physics and the code from those two posts.
 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #36 on: March 09, 2008, 08:06:39 am »

Hi all,

I am trying to create a java pool game which monitors the users performance on how accurately they pocket balls. It is a one player game and I am having trouble with the algorithm related to motion and I used some of your code to implement that part but I am not getting the same result.
Lets say that no collision occurs, when a force is applied upon the cue Ball, it travels along the right direction but it deviates from the trajectory more and more and end up in the wrong place. Could anyone tell me what the problem is? I am really. Thank you in advance.

Sample code from the Pool class
*************************
public void run()
{
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (Thread.currentThread() == animThread)
{
delta = System.currentTimeMillis() - lastTime;
lastTime += delta;
if (ballMoved) AI(delta / 1000.);
startTime += delay;
try { animThread.sleep(Math.max(0, startTime - System.currentTimeMillis())); }
catch (InterruptedException e) {  break; }
}
}

public void travel(double dt)
{
for (int i = 0; i < Arr.size(); i++)
Arr.getBallAt(i).collision(cueBall);

cueBall.travel(dt);

for (int i = 0; i < Arr.size(); i++)
Arr.getBallAt(i).travel(dt);//ball.AI(dt);

for (int i = 0; i < Arr.size(); i++)
ballMoved = cueBall.check(Arr.getBallAt(i));

repaint();
}

Sample code for Ball Class
********************
public boolean travel(double dt)
{
if (!ballMoved)
return false;

double velocity = Math.sqrt(vx * vx + vy * vy);
if (velocity != 0. && !inHole)
{
dx = vx / velocity;
dy = vy / velocity;
velocity -= 20 * dt;
if (velocity < 0.)
{
vx = 0.;
vy = 0.;
}
else
{
vx = velocity * dx;
vy = velocity * dy;
}
}
x += vx * dt; //increment the x value
y += vy * dt; //increment the y value

if(isWithinLimits(x, y))
{ /*no action taken*/ }
else //if the x and y coordinate value are larger than the limits
//which are the table boundary
changeDirection();

if (inHole && vx == 0 && vy == 0)
{
if (x < diameter)
x = -radius;
else if (x > xmax)
x = xmax + radius;
else
x = xmax;
if (y < diameter)
y = -radius;
else if (y > ymax - diameter)
y = ymax + radius;
ballMoved = false;
}
return inHole || checkhole();
}

public boolean isWithinLimits(int xx, int yy)
{
if (xx > xmin && xx < xmax && yy > ymin && yy < ymax)
return true;
else
return false;
}
public void changeDirection()
{
if (inHole)
{
vx = 0.;
vy = 0.;
return;
}

if (x < xmin)
{
x = 2*xmin-x;
vx = -vx;
}
else if (x > xmax)
{
x = 2 * xmax - x;
vx = -vx;
}

if (y > ymax)
{
y = 2 * ymax - y;
vy = -vy;
}
else if (y < ymin)
{
y = 2*ymin-y;
vy = -vy;
}
}//end of method

 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #37 on: March 09, 2008, 03:10:56 pm »

Please provide explanation for the following code:
public void travel(double dt)
{
for (int i = 0; i < Arr.size(); i++)
Arr.getBallAt(i).collision(cueBall);

cueBall.travel(dt);

for (int i = 0; i < Arr.size(); i++)
Arr.getBallAt(i).travel(dt);//ball.AI(dt);

for (int i = 0; i < Arr.size(); i++)
ballMoved = cueBall.check(Arr.getBallAt(i));

repaint();
}
 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #38 on: March 09, 2008, 10:48:34 pm »

public void travel(double dt)
{
//Arr is an array that contains all the balls except the cue ball
//so each time all the balls are checked if the cueball has collided with them
for (int i = 0; i < Arr.size(); i++)
Arr.getBallAt(i).collision(cueBall);

//cueBall moves from its initial position
cueBall.travel(dt);

//the method travel is called on all the other balls and they will only move if their velocities is not 0
for (int i = 0; i < Arr.size(); i++)
Arr.getBallAt(i).travel(dt);

for (int i = 0; i < Arr.size(); i++)
ballMoved = cueBall.check(Arr.getBallAt(i));

repaint();
}

 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #39 on: March 10, 2008, 12:05:10 am »

You were using the Euler's method to move the particle one step forward.
However, the error will accumulate unless it is a constant motion.
There is a constant friction force in your case a= 20;  (from your code:  velocity -= 20 * dt;)
The velocity is changing between time t to t+dt (it is not the same between time t and time t+dt).
However, because it is in a constant acceleration mode. so the velocity change linearly.
You should use the average velocity to calculate the displacement (i.e. use Midpoint method instead of Euler's method).

Your problem is mainly due to how you calculate the change in velocity.

dx = vx / velocity;
dy = vy / velocity;
velocity -= 20 * dt;

I know you were trying to calculate the component, but the ratio of vx,vy will be different before and after you change the velocity. That is the reason why the moving direction was changed.

Because it is a constant force acting on the particle. So both vx and vy will change the same amount,
Just use vx-=a*dt; vy-=a*dt;  will be fine.
To make the calculation more accurate.
define vxs,vys before the above change:
i.e.
//save the previous velocity value
vxs=vx;
vys=vy;
//calculate the new velocity
vx-= a*dt;
vy-=a*dt;
// calculate the displacement
x+= (vxs+vx)*dt/2;
y+= (vys+vy)*dt/2;

The above method is also called as "Midpoint Method".
 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #40 on: March 10, 2008, 02:38:30 am »

I think I did the necessary changes but it got worse. The cue ball is moving in different directions, sometimes it stops and starts moving in a random direction.

public boolean travel(double dt) {

if (!ballMoved)
return false;
//for a 2D space the velocity operations is treated as a vector
double velocity = Math.sqrt(vx * vx + vy * vy);

//BACKUP the previous velocity value
double vxs = vx;
double vys = vy;

if (velocity != 0. && !inHole)
{
dxx = vx / velocity;
dyy = vy / velocity;
velocity -= a * dt;

if (velocity < 0.)
{
vx = 0.;
vy = 0.;
}
else
{
/* Average Velocity = Displacement / Change in time
OR  (x2 - x1)/ (t2 - t1)
*/
//CALCULATE THE NEW VELOCITY
//before it was vx = velocity * dxx;// vy = velocity * dyy;
vx -= a * dt;
vy -= a * dt;
}
}
//CALCULATE THE DISPLACEMENT
//before it was x += vx * dt;  y += vy * dt;
x += (vxs+vx) * dt/2; //add value to the x coordinate
y += (vys+vy) * dt/2; // add value to the y coordinate

if(isWithinLimits(x, y))
{ /*no action taken*/ }
else if(inHole)
{
vx = 0.;
vy = 0.;
}
//if the x and y coordinate value are larger than the limits
//which are the table boundary
else
changeDirection();
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #41 on: March 10, 2008, 03:40:41 pm »

1. You did not do the same as I suggested. You are still using the code as:
dxx = vx / velocity;
dyy = vy / velocity;
velocity -= a * dt;
Applied the change to vx,vy directly.

2. if(vx<0) vx=0; // this only work if vx>0 at t=0, what if vx<0 at t=0;
 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #42 on: March 12, 2008, 08:42:13 am »

It still not working and it seems to be worse than before in terms of how long the ball is supposed to travel after a certain force is used on it. Also it is not going in the right direction. Did I miss anything?

public boolean travel(double dt) {

if (!ballMoved)
return false;

//for a 2D space the velocity operations is treated as a vector
double velocity = Math.sqrt(vx * vx + vy * vy);

//BACKUP the previous velocity value
double vxs = vx;
double vys = vy;

if (velocity != 0. && !inHole)
{
if (velocity < 0.)
{
vx = 0.;
vy = 0.;
}
else
{
//CALCULATE THE NEW VELOCITY
vx -= a * dt;
vy -= a * dt;
}
}
//CALCULATE THE DISPLACEMENT
x += (vxs+vx) * dt/2;
y += (vys+vy) * dt/2;

if(isWithinLimits(x, y))
{ /*no action taken*/ }
else if(inHole)
{
vx = 0.;
vy = 0.;
}
//if the x and y coordinate value are larger than the limits
//which are the table boundary
else
changeDirection();
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #43 on: March 12, 2008, 09:42:42 am » posted from:Taipei,T\'ai-pei,Taiwan

1. Oops!  Sorry, the drag force should not be a constant.
It will keep in the same direction if you changed it to

vx-=b*vx;
vy-=b*vy;

The b will determine how fast the particle will be stopped.
You can try it with 0.1 and adjusted as you need. May be make it as an adjustable parameter.

2. Because velocity = Math.sqrt(vx * vx + vy * vy);
So velocity will always be positive or zero.

 Logged
nadia_777
Newbie

Offline

Posts: 7

 « Embed this message Reply #44 on: March 12, 2008, 10:55:54 pm »

I am not really good in physics so let me recapitulate what you said to the best of my abilities. You said that the drag force shouldn't be a constant then does that mean that the ball will only come to a halt when:
-vx = 0 and vy=0 but also when the force 'a' which initially had a value of 0.1  [double a = 0.1] gets its value reduced and reaches 0.0 at the same time that vx and vy get the value of 0?

Is there a formula to be used to gradually reduce the speed of a ball in motion and then stop the ball at a certain point and time?
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #45 on: March 21, 2008, 07:57:59 pm »

If the force is proportional to velocity.

F= -b*v
From Newton's Law:
F= m dv/dt =-b*v
Then, dv/dt=-(b/m)*v

If the velocity V(t=0)=V0
Then the solution for the above differential equation is
V(t)=V0*e-bt/m

The velocity will not reach zero from mathematic point of view.
But it's magnitude will reduce to nearly 2% of its original value by the same time step t=4*(m/b) seconds.
if m/b=1s, V0=100m/s,  (the following values are estimated values, use exponential function to calculate it's exact value.)
at t=4s, V0=100*0.02=2m/s,
at t=8s, v0=2*0.02=0.04m/s,
at t=8s, v0=0.04*0.02=0.0008m/s
...

 Logged
RuDZiK
Newbie

Offline

Posts: 1

 « Embed this message Reply #46 on: April 29, 2008, 06:24:54 pm »

Dear Fu-Kwun Hwang!
I really interested in phisics generally, and your Billiard sample in particular. I was working on a project about ball collision, but it was quite difficult to find any simple examples, scientific literature or detailed articles about 2D-collision. I found your article very useful and clear for beginners, as well as for phisics/sciense interested people. Thank you for your help, I really moved forward in my work.

With best wishes

RuDZiK
 Logged
Arturas
Newbie

Offline

Posts: 1

 « Embed this message Reply #47 on: July 23, 2008, 09:01:42 pm »

Hello Fu-Kwun Hwang

Very interesting! could you, please, send me the source code of this applet?

Thank you very much.
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #48 on: July 23, 2008, 09:57:22 pm »

The source code was added as an attachement in the first message. Please download it by yourself.
However, it was written almost 10 years ago with JDK1.0.2.  You might need to re-write some code to work with current JDK version.
 Logged
rpaolet
Newbie

Offline

Posts: 4

 « Embed this message Reply #49 on: September 04, 2008, 11:15:58 pm »

Ciao Fu-Kwun Hwang,

i'm a italian student and i'm working on a exame of architecture.
Your forum is very interesting and i found your billiards code similar to my project,but i'd like to change some properties like:
-delete the second ball and  erase the holes on the table
-Insert the class swing.timer for add button start and stop to the GUI.

I'm trying to change the code but i didn't know the application doesnt' work.
Could you help me???

Thank you for your response and time.
ciao
Roberto
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #50 on: September 05, 2008, 12:00:03 am »

Do you mean that you just want to have balls moving inside a rectangle box and collide with each others?
 Logged
rpaolet
Newbie

Offline

Posts: 4

 « Embed this message Reply #51 on: September 05, 2008, 05:35:05 am »

I'd like to have a ball in the rectangle box without holes that i can setup the position,the direction and the power(speed).
Then you can use the start/stop button for the moving.
Required:
-simulate the moving of the ball by use the java.swing.timer. class
-create a GUI
-rolling friction
-change the power(speed) when the ball is still moving

Thank you in advance.
 *** There are 1 more attached files. You need to login to acces it! Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #52 on: September 05, 2008, 09:29:16 pm »

Registed user can get files related to this applet for offline access.
Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
If java program did not show up, please download and install latest Java RUN TIME

So you just need one ball in the rectangle?
What do you mean by rolling friction?
If the rolling friction is large enough then the ball's motion is moving without slipping.
It means that there is no energy loss.
What about the collision between the ball and the wall?
If it is elastic collision, then the energy is also conserved.

I will create the simulation with easy java simulation. It is easier to create it this way.

Is this what you want? You can use mouse to drag and drop either particle position or velocity vector (click checkbox to show velocity). Change b value to add drag forces or clcik constant drag.

Registed user can get files related to this applet for offline access.
Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
If java program did not show up, please download and install latest Java RUN TIME
 Logged
rpaolet
Newbie

Offline

Posts: 4

 « Embed this message Reply #53 on: September 06, 2008, 06:38:14 am »

Yes the simulation is perfect, thank you very much for your help.
i don't understand some things;the code is written used the javax.swing.timer  and can modify or add of the code?

Thank you a lot for your collaboration.
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #54 on: September 06, 2008, 04:52:18 pm »

It was not written directly with java. I create it with a tool called Easy Java Simulation

It is actually a java code generator. It is for people who is not so familiar with java but has strong background in physics/science.
You just define variables/ write equations to exppress relation between variables and equations to indicate how variables change with time. EJS will generate the java code for you. It also has graphic user interface so you can drag and drop graphic elements to create the view.
You can download the EJS source and find out how I did it(You will need to download and install EJS). You can also modify it and generate new code.

If you just want to see how it look like click "load ejs as signed applet" and allow browser to load EJS into your browser. You will be able to run EJS within browser, find out the model, moify it and generate new simulation.
 Logged
rpaolet
Newbie

Offline

Posts: 4

 « Embed this message Reply #55 on: September 07, 2008, 06:22:10 am »

Grazie, you have been very clearly.
I'm not sure that i can use this EJS for my exame,however thanks a lot because i didn't know the EJS suite and it's very fantastic!!!!!!

Ciao
Roberto
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #56 on: September 07, 2008, 11:15:43 am »

If you are interested in java programming, then I will suggest you write java code by yourself.
However, if you are interested in science and modeling, it will be easier and more effective to use EJS. :-)
Check EJS web site and find out information about it. I have created many flash videos with step by step instruction to show new users how to use EJS to generate new simulations. However, it is displayed in Chinese interface. Sorry!
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3080

 « Embed this message Reply #57 on: September 07, 2008, 05:46:20 pm »

There is a bug in the code. It is corrected today.
 Logged
cuebux
Newbie

Offline

Posts: 1

 « Embed this message Reply #58 on: November 03, 2010, 02:13:16 am » posted from:Eau Claire,Wisconsin,United States

This is a good simulation. Is there some sort of equation that would help better understand the other factors a player would face in billiards like ball squirt, throw, bounce rates, deflection? Here is a video of the Meucci Black Dot Shaft Demonstration showing squirt in action.

Perhaps a database driven application to allow input of collected data against different materials and test variables. Anyone want to partner up?
E.G Humidity, Sea Level, Air pressure etc.
 Logged
jarvo250
Newbie

Offline

Posts: 9

 « Embed this message Reply #59 on: December 21, 2010, 10:37:50 pm » posted from:Grimsby,North East Lincolnshire,United Kingdom

I've been looking at this over the last couple of days as I have been trying to remove the, reset, clear and drop down options from the applet.

I'm not having much luck with it and constantly getting compile errors....Any chance there is  version without these options on??
 Logged
 Pages: 1 [2] 3   Go Up
"Nothing in life is to be feared, it is only to be understood." ..."Marie Curie 1867-1934, Polish born French Physicist, Twice Nobel Prize Winner- Physics and Chemistry)"
Jump to:

 Related Topics Subject Started by Replies Views Last post physics of Rainbow « 1 2 » Optics Fu-Kwun Hwang 39 561662 June 02, 2015, 02:06:40 pm by michael00 I find this site is fantastic, especially billiards Wave 0 19946 March 04, 2004, 12:20:42 am by Physics in action at different scales Molecular Workbench concord 2 16147 September 21, 2013, 07:39:05 pm by tmoody75 EJS physics example/board:23-100- Questions related to EJS andresgo 6 9864 June 06, 2011, 08:37:24 am by lookang
Page created in 0.129 seconds with 23 queries.since 2011/06/15