FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   bouncing balls part1
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: bouncing balls part1  (Read 407 times)
kemo

Email
bouncing balls part1
« on: Oct 8th, 2003, 3:31pm »

hello people,
 
I 've got 2 balls bouncing inside the window, but i can' t bounce them from each other. Can someone help/explain me how can i bounce balls from each other?
 
kevin

WWW
Re: bouncing balls part1
« Reply #1 on: Oct 8th, 2003, 5:23pm »

I'm by no means an expert but the basic way to approach this is similar to what you've done already.
 
Currently you're checking to see if the ball is hitting the wall. You need to add another check to see if it's hitting the other ball(s) aswell. Once you have the x & y co-ordinates of the balls this shouldn't be to difficult.
 
Get the distance between the center point of ball1, and the center of ball2. If the distance is great than the radius of ball1 + ball2 then they've hit.
 
http://www.jmckell.com/ is a director site, but it explains the theory well and you should be able to put it into practice in processing.
 
This basic collision example should help you on your way too:
http://www.proce55ing.net/learning/examples/collision.html
 
Good luck,
 
Bijeoma

myloveiloved
Re: bouncing balls part1
« Reply #2 on: Oct 8th, 2003, 6:17pm »

heres a link to one of the first programs i wrote in p5. it demonstrates the usage of circle to circle collision. each time the circles collide a ring is added inside the circle and the colliding area is also filled. the code maybe a little messy. i commented minimally.
 
http://www.rit.edu/~bei6453/p5/circle_to_circle_collision/
 
information not relevant to your question:  
click to stop a circles movement
click and drag to drag..
and click again after to start a circles movement back up again
 
bryan
« Last Edit: Oct 8th, 2003, 6:19pm by Bijeoma »  
kemo

Email
bouncing balls part2
« Reply #3 on: Oct 9th, 2003, 1:05am »

The balls are bouncing
 
The problem now with the bouncing balls is that it doesn' t bounce smoothly if it touches another ball.
 
look www.geocities.com/ovinoo
 
mKoser

WWW Email
Re: bouncing balls part1
« Reply #4 on: Oct 9th, 2003, 1:26am »

Quote:
http://www.jmckell.com/ is a director site, but it explains the theory well and you should be able to put it into practice in processing.

 
uhh... now there's a nice link for the lingo-folks!
(thanks)
 
+ mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
benelek

35160983516098 WWW Email
Re: bouncing balls part2
« Reply #5 on: Oct 9th, 2003, 4:51am »

on Oct 9th, 2003, 1:05am, kemo wrote:
The problem now with the bouncing balls is that it doesn' t bounce smoothly if it touches another ball.

 
The problem is occuring because you're simply reversing the velocities of the balls, not reflecting them.
 
it's a little intensive in terms of maths doing a full-on accurate reflection, but you can find an intuitive simplified angle of reflection by calculating the angle between the direction of one ball, and the center of the other ball.
 
argh... i've gone and made a diagram, but my web hosting service is playing games
 
lemme know if you need any further explanation.
 
Pages: 1 

« Previous topic | Next topic »