# Swept circle - line segment collision (again)

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

## Recommended Posts

I've spent a hell of a long time trying to figure this out, reading replies to lots of threads (including my own), and well frankly, I just can't hack it. So I'm going to start from scratch here and hope somebody can help. By the way, this is all 2 dimensional. We have a circle of radius r, which is swept along a line segment with start and end points. We need to determine if this swept circle collides with another line segment, also with start and end points. We have infinite line equations for both line segments. In addition to whether or not a collision occurred, we need to determine exactly where this circle should stop. I have a very superficial understanding of the math involved in doing this, so please don't assume I know much.

##### Share on other sites
well... iirc i posted complete solution some time ago.....

first,circle-infinite line collision:

you just need to find intersection between two lines and step back to startpoint by r/dotproduct(direction_of_first_line,direction_of_second_line)
to find circle center when it collided.

Alternatively you may move your second line by circle_radius * second_line_normal (make sure your normal points into semiplane where startpoint lines),then find intersection. Even more simple,and very intuitive.

To find point where collision happened you need to find point on second line that are closest to circle center.

If you want collision with finite line segment,find collisions with it's endpoints and use

max(distance_to_collision_with_line,min(distance_to_collision_with_startpoint,distance_to_collision_with_endpoint))
note that if distance_to_collision_with_line< distence_to_collision_with_closest_endpoint,you need to use that closest endpoint as point of collision.

Check if it's within range of first segment.

##### Share on other sites
So as I understand it, you have two segments and a circle. Center of circle can be anywhere on segment 1. You need to know if circle collides with segment 2.

To test collision do this:
- find the projection of center of circle on line 2;
- if distance from center of circle to this projection point is > R (circle radius) then the circle does not intersect segment 2;
- if distance <= R, test if the projection point lies on segment 2 (if it is between its end points);
- if it is, then circle intersects segment 2;
- if it's not, compute the two distances from center of circle to the two end points of segment 2;
- if any of the distances is <= R, the circle intersects the segment, if not, it does not intersect.

Cristian

##### Share on other sites
as i understand,for circle that are MOVING along line_segment_1 from startpoint to endpoint he want to find collision with line_segment_2...

##### Share on other sites
Quote:
 Original post by DmytryAlternatively you may move your second line by circle_radius * second_line_normal (make sure your normal points into semiplane where startpoint lines),then find intersection. Even more simple,and very intuitive.

!

So simple...and obvious...damn, I actually understand it! Now let's just see if I can implement it...

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632994
• Total Posts
3009770
• ### Who's Online (See full list)

There are no registered users currently online

×