I was trying to wrap my head around this problem here but didn’t succeed.
I need to calculate a particle collision within a circle and can’t find the right way for the c
ollisions to be right when they hit an edge with respect to return angle and velocity.
Can somebody help me with this?
float outerRadius = 400;
float x,y = random(10,outerRadius/2);
float xSpeed = 2;
float ySpeed = 2;
float PDistance;
void setup(){
size(500, 500);
translate(width/2,height/2);
background (255);
smooth();
ellipse(0,0,outerRadius,outerRadius);
}
void draw()
{
background(255);
translate(width/2,height/2);
ellipse(0,0,outerRadius,outerRadius);
strokeWeight(2);
point(x,y);
movement();
collisionTest();
}
void movement()
{
x += xSpeed;
y += ySpeed;
}
void collisionTest()
{
float PDistance = sqrt(x*x + y*y);
if (PDistance > outerRadius/2)
{
xSpeed = -xSpeed; //I have no clou how to solve this part here...
ySpeed = -ySpeed; //This only works in a square box, but not inside a circle