Author Topic: Billiards and Physics  (Read 296421 times)

jarvo250

  • Newbie
  • *
  • Posts: 9
Re: Billiards and Physics
« Reply #75 on: December 24, 2010, 12:58:36 am »
I've managed to delete the existing double loop without effecting the applet.

jarvo250

  • Newbie
  • *
  • Posts: 9
Re: Billiards and Physics
« Reply #76 on: December 24, 2010, 01:16:59 am »
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, 02:22:47 am by jarvo250 »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: Billiards and Physics
« Reply #77 on: December 24, 2010, 10:54:42 pm »
?defined movingballs(int xd,int yd,int sizei)
and add the following code inside
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
x=xi;
y=yi;

Then you can initialize new particle with new xi,yi value set.

koclup1580

  • Newbie
  • Posts: -16
    • ????????????
Re: Billiards and Physics
« Reply #78 on: December 29, 2012, 02:22:40 pm »
oh good.