Circle collision detection.

  • 18 years ago

    I hope people actually use this forum, but here goes:
    Does anyone know how to detect collisions with circles in c++?

  • 18 years ago

    Without giving you any C++ code, if you know the X and Y cords of the circles center and the radius of each, this is simple.


    You can find the distance between the two circles centers with this formula.
    Distance = Sqr(Abs(Cir1X – Cir2X)  ^ 2 + Abs(Cir1Y – Cir2Y)  ^ 2)
    Where Sqr returns the square root of a number and Abs returns the absolute value of a number.


    Now that you have the distance from the centers, if the sum of the two radiuses are greater then or equal to the distance then the circles are touching or overlapping.

  • 18 years ago

    Whats with the vb code?, Anyway il have to try again since that didn't work the first time.
    Thanks

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth