Collision Detection Between a Circle and a Line Segment

Collision between Segment AB and circle C (radius r). Let’s remember a little of vector algebra and pythagorean theorem.
The height of the right-angle triangle ACD is what we need to compare with radius.

This is a segment and not an infinite line; When the triangle height fall outside of the segment (look at the picture aside, height < radius but still no collision) we can compare directly length of the two vectors AC and AB with radius; It’s better comparing squared length.

Another cool use of #cppinsights. You can easily show how floating points are represented and why we need a precision check when comparing two doubles. Note that, negative powers of two are represented exactly.
@Andreas__Fertig
https://t.co/OI0QytX09K
https://t.co/KzDsCwHz57