Rishi Malhotra
Rishi Malhotra

Reputation: 15

Finding coordinates of the circumference of circle in pygame

in pyGame, I drew 2 circles. 1 that is stationary and one that moves with the arrow keys. So, I want the moving circle to bounce back once it touches the stationary circle( I want it to bounce off the stationary circle not the window.)

To do that I need to find the coordinates of the circumference of the stationary circle. But I do not know the specific module. Can someone suggest a module or an alternate solution.

Upvotes: 0

Views: 166

Answers (1)

Owen Tourlamain
Owen Tourlamain

Reputation: 174

What you actually need is to find each circles center and radius, then check the distance between the centers, if the distance is less than or equal to the two radii then you know you have a collision. I'll give an example to help:

Say you have circle A, fixed at the point (0,0) with a radius of 5px.

Circle B is at (0,10) with a radius of 3px, which is moving towards the point (0,0).

So, at first we know the distance between the two centers ((0,0) and (0,10)) is 10px, and since 10 is less than 5+3 we know the two circles are not touching.

Now at some point circle B will get to the point (0,8), at this moment when we check the distance between the circles we will get 8, which is equal to 5+3, so we have a collision.

I don't know which libraries and functions you will need to do this, but hopefully this has helped you find the right thing to search for. Basically you need to get the centers, the radii and the distance between two points (the two centers).

Upvotes: 1

Related Questions