NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
December 15, 2017, 03:24:43 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Wisdom consists of the anticipation of consequences. ..."Norman Cousins(1913-1990, American author)"
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: 1 2 [3]   Go Down
  Print  
Author Topic: Billiards and Physics  (Read 262080 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #60 on: December 21, 2010, 11:02:03 pm » posted from:Taipei,T'ai-pei,Taiwan

The applet was created many years ago (more then 10 years) with JDK1.0.2
You might get error if you use latest jave to compile it (because java has severla major change over the year)

It should work fine if you use JDK1.0.2
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #61 on: December 22, 2010, 06:47:16 am » posted from:Grimsby,North East Lincolnshire,United Kingdom

The applet was created many years ago (more then 10 years) with JDK1.0.2
You might get error if you use latest jave to compile it (because java has severla major change over the year)

It should work fine if you use JDK1.0.2


It compiles fine if I don't alter the code at all....I just want the levels, buttons and drop down part removed from the code. I am attempting to create a snooker game, and I am having real trouble getting started, and ideally would like to use this as a base to get going, but I don't want the options I mentioned. When I remove the codes I think are related to it, it never compiles correctly.....really tearing my hair out over this...
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #62 on: December 22, 2010, 10:00:31 am » posted from:Taipei,T'ai-pei,Taiwan

I think the problem might be due to "selection list".
If you just remove all those GUI element, then the code can not find the selected level so there is an error.
Find the name for the selection list ,and find code related to that name, replace with proper value/code.
 
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #63 on: December 22, 2010, 07:51:46 pm » posted from:Grimsby,North East Lincolnshire,United Kingdom

I think the problem might be due to "selection list".
If you just remove all those GUI element, then the code can not find the selected level so there is an error.
Find the name for the selection list ,and find code related to that name, replace with proper value/code.
 

Ah yes, thanks so much got it. Now how would I enlarge the area in which the ball bounce off. Its quite small at the minute, and would like to ideally make it bigger....
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #64 on: December 22, 2010, 10:02:49 pm » posted from:Taipei,T'ai-pei,Taiwan

You do not need to re-compile it.
What you need to do is to change the width and height for the applet tag.
Logged
ahmedelshfie
Ahmed
Hero Member
*
Offline Offline

Posts: 954



«
Embed this message
Reply #65 on: December 22, 2010, 10:14:15 pm » posted from:SAO PAULO,SAO PAULO,BRAZIL

Quote
I think the problem might be due to "selection list".
If you just remove all those GUI element, then the code can not find the selected level so there is an error.
Find the name for the selection list ,and find code related to that name, replace with proper value/code.
Do you mean prof i delete this part from code
Quote
Reset","Clear","level1","level2","level3
And after recompile again i do it but what deleted is text in buttons and choose option but buttons stay not deleted only minimum size of buttons.
I tried delete buttons totally to no appear but always give error when i recompile again.  Undecided

 
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #66 on: December 22, 2010, 11:14:33 pm » posted from:Taipei,T'ai-pei,Taiwan

Code:
String rts,STR[]={"Reset","Clear","level1","level2","level3"};
p.add(cb=new Choice());
for(int i=2;i cb.addItem(STR[i]);

The above code add selection list .
If you remove the above code. It will produce error at the following code
      level=cb.getSelectedIndex();
because cb is not exist any more.
Code:
public void reset(boolean status){
level=cb.getSelectedIndex();
clear(status);
running=false;
m.stop();
s.stop();
}


Logged
ahmedelshfie
Ahmed
Hero Member
*
Offline Offline

Posts: 954



«
Embed this message
Reply #67 on: December 22, 2010, 11:30:52 pm » posted from:SAO PAULO,SAO PAULO,BRAZIL

I close also this code 
Code:
// level=cb.getSelectedIndex();
Recompile again but didn't change, i believe i didn't understand good your explain prof.
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #68 on: December 23, 2010, 12:00:11 am » posted from:Grimsby,North East Lincolnshire,United Kingdom

I now have it to the size that I would like....however, the problem now is that I don't wont the balls to appear in random places upon start-up of the applet. I want to set the x and y coordinates of both balls, and still allow them to move freely when colliding.



EDIT: I HAVE NOW FIGURED THIS OUT, HOWEVER, HOW DO I ADD MORE BALLS!!!
« Last Edit: December 23, 2010, 12:15:28 am by mariner1990 » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #69 on: December 23, 2010, 12:23:40 am » posted from:Taipei,T'ai-pei,Taiwan

1. The position was random because there are assigned as
      x=Math.random()*wx;
      y=Math.random()*wy;

You need to change all those code to whatever you want.

2. There are only two balls in the code
movingballs m,s;

You need to add more and initialize each ball.
If you have more than two balls. You need a double loop to take care of collision between all balls.
e.g. ball A,B,C
You need to take care of collision between AB, BC and CA

You are welcomed to check out Browian motion or particle model for solid/liquid/gas states in 3D

3. If there is any error when compile the code, check out the error message (it will point out the line numeber where the error occur) and try to solve it according to what the message say.



Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #70 on: December 23, 2010, 01:16:55 am » posted from:Grimsby,North East Lincolnshire,United Kingdom

Ok so I have a new ball appearing, but it appears under an existing ball (one of the originals that was in the code). And I have it so that the white ball collides with it but the ball doesnt move.

I assume this is to do with that double loop you were on about.....where abouts is this in the code and what do I add.
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #71 on: December 23, 2010, 06:54:55 am » posted from:Grimsby,North East Lincolnshire,United Kingdom

I have multiple balls on screen now, and each ball collides successfully. The only problem I have now is with the random positioning of the balls. I know how to change it so its not random. However, when I do change it two of the three balls go into the same place, and then the collisions are messed up. How can I set the position and allow the balls to collide.
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #72 on: December 23, 2010, 07:05:14 pm » posted from:Taipei,T'ai-pei,Taiwan

The code to process collision will fail if you have two balls at the same position. (This would not happened in real life).

If you have more than two ball , i.e. n ball
You need a double loop to process possible collision between any two balls.
The original code only process collision between two ball.
Change it a function e.g. collision(i,j) which will process collision between particle i and j.
The double will look like
for(int i=0;i<n;i++){
 for(int j=i+1;j<n;j++){
   collision(i,j);
 }
}

You are welcomed to check out Collision 2D to find more information.
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #73 on: December 23, 2010, 10:02:45 pm » posted from:Grimsby,North East Lincolnshire,United Kingdom

The code to process collision will fail if you have two balls at the same position. (This would not happened in real life).

If you have more than two ball , i.e. n ball
You need a double loop to process possible collision between any two balls.
The original code only process collision between two ball.
Change it a function e.g. collision(i,j) which will process collision between particle i and j.
The double will look like
for(int i=0;i<n;i++){
 for(int j=i+1;j<n;j++){
   collision(i,j);
 }
}

You are welcomed to check out Collision 2D to find more information.

Am totally lost. There is already something similar to that in the code. Are you saying I need to do that again or not?

Honestly can't get it done....
« Last Edit: December 23, 2010, 11:00:38 pm by jarvo250 » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #74 on: December 23, 2010, 11:40:45 pm » posted from:Taipei,T'ai-pei,Taiwan

You do not need to add more loop if you already have double loop in your code.

However, you have to do it correctly.
I do not know how you did it and I do not know how can I help?
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #75 on: December 23, 2010, 11:58:36 pm » posted from:Grimsby,North East Lincolnshire,United Kingdom

I've managed to delete the existing double loop without effecting the applet.
Logged
jarvo250
Newbie
*
Offline Offline

Posts: 9


«
Embed this message
Reply #76 on: December 24, 2010, 12:16:59 am » posted from:Grimsby,North East Lincolnshire,United Kingdom

I have more than two balls colliding...i.e AB, BC, CA can all collide. The problem I have is with placing balls B and C at set coordinates. I have ball A working in set coordinates, but ball B and C share the same X and Y coordinates

i.e: x=Math.random()*wx;
   y=Math.random()*wy;

When i change the above to say, 100 and 200, both B and C balls move to that place. I need separate X and Y coordinates to be assigned but also work in the collision method.

I have new instance of a ball which allows me the third ball, but the new instance has the same value as B the second ball.
« Last Edit: December 24, 2010, 01:22:47 am by jarvo250 » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #77 on: December 24, 2010, 09:54:42 pm » posted from:Taipei,T'ai-pei,Taiwan

Idefined movingballs(int xd,int yd,int sizei)
and add the following code inside
Code:
x=Math.random()*xd;
y=Math.random()*yd;

That is the reason why x,y are created randomly.

You can define something like 
movingballs(int xd,int yd,int xi,int yi,int sizei)
if you need to assign it to a new position (xi,yi)
and change the above code to
Code:
x=xi;
y=yi;

Then you can initialize new particle with new xi,yi value set.
Logged
koclup1580
watchlist
Newbie
*
Offline Offline

Posts: 16


WWW
«
Embed this message
Reply #78 on: December 29, 2012, 01:22:40 pm » posted from:,,Satellite Provider

oh good.
Logged
Pages: 1 2 [3]   Go Up
  Print  
Wisdom consists of the anticipation of consequences. ..."Norman Cousins(1913-1990, American author)"
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
physics of Rainbow « 1 2 »
Optics
Fu-Kwun Hwang 39 548053 Last post June 02, 2015, 02:06:40 pm
by michael00
I find this site is fantastic, especially billiards
Wave
0 19712 Last post March 04, 2004, 12:20:42 am
by
Physics in action at different scales
Molecular Workbench
concord 2 15835 Last post September 21, 2013, 07:39:05 pm
by tmoody75
EJS physics example/board:23-100-
Questions related to EJS
andresgo 6 9274 Last post June 06, 2011, 08:37:24 am
by lookang
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.074 seconds with 23 queries.since 2011/06/15