We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Collision detection inside a circle
Page Index Toggle Pages: 1
Collision detection inside a circle (Read 820 times)
Collision detection inside a circle
Apr 6th, 2009, 8:27am
 
Hi all,

I have been trying to work this out but I am going no where, so far I detect when the particles reach the circle bounds, using the pythagorean formula, easy, but the problem is the angle they bounce, can you give me a hint as where to look for a solution?

I am reading the Keith Peter Actionscript Animation chapter about Coordinate Rotation, Bounce of an Angle, but I cant work it out how to apply it inside a circle.

Thanks for your help
rS
Re: Collision detection inside a circle
Reply #1 - Apr 6th, 2009, 9:17am
 
You need to compute the angle of the tangent line at the point where the collision takes place, and then perform ordinary bouncing off of that imaginary flat surface.  When something bounces off a flat surface, the angle at which the object approaches the surface equals the angle at which it bounces.  Usually these are measured in degrees away from the perpendicular.

I would start by computing the angle from the point of intersection to the center of the circle (use atan() or atan2() for this).  The tangent at that point is then 90 degrees away from that angle.  Shouldn't matter if you add or subtract 90 degrees, the result is the same.
Re: Collision detection inside a circle
Reply #2 - Apr 7th, 2009, 3:02am
 
Here is my setup

particles have vx and vy properties for the velocity

particle.vx = random(2);
particle.vy = random(2);

they go inside a circle call limitArea

limitArea has a radius;

limitArea.radius = 200;

//so I check for the distance between the partice and the center of the limitArea

float dx = limitArea.x - x;
float dy = limitArea.y - y;
float dist = sqrt(dx * dx + dy * dy);


//if the distance is greater than limitArea radius
if (dist > limitArea.radius) {
     var angle:Number = atan2(dy, dx);
     var cos:Number = cos(angle);
     var sin:Number = sin(angle);
     
//reposition the particle inside the limitArea
     x = limitArea.x + (cos * -(limitArea.radius - 0.5));
     y = limitArea.y + (sin * -(limitArea.radius - 0.5));
     
       //change the velocity direction but this is wrong!!! here is where I need help
     vx *= bounce;
     vy *= bounce;
}

x += vx;
y += vy;


so as you can see the vx and vy *= -bounce is wrong as they dont bounce properly.

I belive the solution is in the formula, from the coordinate rotation
new x = cos(angle) * x - sin(angle) * y;
new y = cos(angle) * y + sin(angle) * x;

where they rotate position and velocity back and forward, but I cant get it to work

Any help? ...you! Thanks
rS
Re: Collision detection inside a circle
Reply #3 - Apr 21st, 2009, 4:01am
 
For those how are interested

greate tutorial

http://www.tonypa.pri.ee/vectors/tut09.html

I forgot all about this, come on math come back to me...

Cheers
rS
Page Index Toggle Pages: 1