Circle to Polygon Collision Detection (Solved)

Started by
10 comments, last by Jouei 14 years, 7 months ago
once yo have the closest point on the polygon, you can work out the MTD quite easily, and also the collision test.

If the distance squared is greater than the radius of the sphere squared, no collision, else....


bool collide(const Sphere& sphere, const Polygon& polygon, Vector& mtd){    Vector closestPoint;    float distance_squared = closestPointOnPolygon(sphere.position, sphere.radius, polygon.vertices, polygon.numvertices, closestPoint);    if(distance_squared > (sphere.radius * sphere.radius))        return false;    float distance = sqrt(distance_squared);    mtd = (sphere.position - closest) * ((sphere.radius - distance) / distance);    return true;}


a small demo.

I use Dave Eberly's triangle distance routine. It's more optimised than the code above, and returns a 's' and 't' values, the parametric representation of the point (that you can use to say, interpolate for texture coordinates and so on).

Everything is better with Metal.

Advertisement
Well i got that working nicely now. I would like to thank you all for your input and taking the time to help this math gibbled me.

It seems everything is working as expected i still got a bit to go to improve my collision system but the hard part i believe is done and i am truly grateful for that :)

So thanks again and i will now marked this Post as solved when i get it all done i will probably post all the code and make a doc for it as it is for C# and XNA witch i seem to find is most commonly used by newer game programmers.

Best regards Jouei.

This topic is closed to new replies.

Advertisement