I''m not very good at maths but I think that the best solution to my problem is using vector math. I want to make a very good (or perfect) collision detection function which detects if lines/circles are colliding. There would be 3 functions:
BOOL LinesColliding(line1 coordinates, line2 coordinates)
BOOL CirclesColliding(circle1 pos and rad, circle2 pos and rad)
BOOL LineAndCircleColliding(line coordinates, circle pos and rad)
Checking circles together is easy because you just have to check the distance between them. But I don''t know how to do it with lines. Could someone please help?
If you calculate the distance from a point on a line to the center of the circle that gives you the hypotenuse of a right triangle. The dot product of a vector from that point to the center of the circle with a unit vector pointed down the line gives you a projection of that vector onto the line, i.e. a second side. You need the third side, but I''ll assume that given the length of two sides of a right triangle that you can find the third. If that third side is less than the radius then the point of intersection can be found from the the third side and the radius of the circle. Those are two side of another right triangle with the radius of the circle the hypotenuse. The third side of that right triangle is the distance along the line to the two points of intersection with the circle.