Quote:If you're referring to Wasting Time's post, than yes it will work; it is exactly the correct solution.
Wasting Time's solution will not work in some cases, firstly a triangle has hundreds of different centers but if you chose any fixed point inside the triangle then the circle can be positioned in such a way that it is intersecting the tringle but the algorithm will not return true, for example: if you had a long thin triangle (longer than the diameter of the circle) and the circle was close to the further away vertex.
Quote:The standard implementation of point-to-triangle distance assumes the triangle is a "solid". You are treating the triangle as if it is a wireframe. In the standard implementation, if the point is inside (or on) the triangle, the distance is zero.
I dont actually suggest using the distance from the center of the circle to the triangle for the collision detection test.
What I was describing takes first a point/triangle test then a circle/wireframe triangle test which in combination handles every case.
Since some code would probably make more sense than my explanation heres my implementation of what I was describing from line 12 onwards:
int SphereIntersectsTriangle(CVector sphere_center, float radius, CVector A, CVector B, CVector C, CVector N, float d) { float k = d-sphere_center.Dot(N); CVector center_projected_onto_triangle = sphere_center+N*k; float radius_at_projected_point_squared = radius*radius-(sphere_center-center_projected_onto_triangle).Norm(); // Check that the sphere intersects the triangles plane if(radius_at_projected_point_squared < 0) return 0; ////////////////// From here on its just circle a triangle intersection test: // Check if the point is inside the triangle if(BPPointInTriangle(center_projected_onto_triangle, A, B, C)) return 1; // check if the projected point is close enough to any of the triangles edges k = ClosestPointOnLineToPoint(A, B, center_projected_onto_triangle); if(k < 0) k = 0; else if(k > 1) k = 1; if((A + (B-A)*k - center_projected_onto_triangle).Norm() < radius_at_projected_point_squared) return 1; k = ClosestPointOnLineToPoint(B, C, center_projected_onto_triangle); if(k < 0) k = 0; else if(k > 1) k = 1; if((B + (C-B)*k - center_projected_onto_triangle).Norm() < radius_at_projected_point_squared) return 1; k = ClosestPointOnLineToPoint(C, A, center_projected_onto_triangle); if(k < 0) k = 0; else if(k > 1) k = 1; if((C + (A-C)*k - center_projected_onto_triangle).Norm() < radius_at_projected_point_squared) return 1; return 0; }