# Frame Independent Circle-Detection (Flash MX Game Design Demystified)

I am currently learning Frame Independent Circle Circle Detection from the book entitled Flash MX Game Design: Demystified. I am stuck on the theory behind detecting whether two circles have collided. For reference to this question, the section can be read at

(this will take you directly to the page where this section begins in the book, as you can view it on Google Books).

I am dumfounded about the whole way that this equation is done in theory (I have not even got on to the ActionScript however I believe if I understand the theory behind the equation I will be able to easily apply the ActionScript).

It is hard for me to ask any questions at all in relation to this section as I am really confused about the whole process. The book does not explain it in any length so I am hoping someone can give me a thorough explanation of how this works.

In section 1; Write equation for the x and y positions of both circles. These equations are based on the x and y speeds.

The formula given is x1 = xl1 + xmov1*t. I do not understand how t applies to the situation practically when time is measured in frames. It says in the book that t represents the time starting from the end of the previous frame, wouldn’t t always be equal to 1 then since the time starting from the previous frame is one (the time between the previous frame and current frame is always 1 isn’t it).

In section 2; Use the equations for the x and y positions of both circles to write an equation for the distance between the two circles.

This part I understand, pretty much the distance formula:

distance = squareroot((x2-x1)^2 + (y2-y1)^2) is used to determine the length at which the circles have to be in order for them to be colliding. So if the length between circles <= distance then the circles are colliding.

In section 3; Set the distance as the sum of the radii, and solve for time.

Firstly, isn’t the distance for the sum of the radii all ready discussed in step 2. After all distance = squareroot((x2-x1)^2 + (y2-y1)^2) has all ready set the distance as the sum of the radii. However, I guesss it is solving for time that is the difficult part, it even states it in the book.

If you read the start of page 105 you will know what I am talking about:

We must insert the equations for x1, y1, x2 and y2. We then square both sides of the equation (to get rid of the square root sign). What we are left with is a quadratic equation.

The book then goes on to define a number of constants, these are:

a = -2xmov1xmov2+xmov1^2+xmov2^2

It goes on and on like this.

Finally, and this is where I am completely lost, the final quadratic equation formula to solve for time is stated as:

t1 = (-hsquareroot(h^2-4gk))/(2g)

and

t2 = (-hsquareroot(h^2-4gk))/(2g)

The book then goes on to do a practical example in ActionScript.

Can someone please explain this to me in a way that I can understand. Any help would be greatly appreciated, thank you for taking your time and I will be very grateful to anyone that hammers this point into my head :wasted:.