#### Archived

This topic is now archived and is closed to further replies.

# Collision detection with lines&circles

This topic is 6332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! 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? Thanks Floru

##### Share on other sites
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.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013377
×