Sign in to follow this  

Swept circle - line segment collision (again)

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Dmytry
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.


!

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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this