7 views (last 30 days)

Suppose we know the start point (x1,y1), the end point (x2,y2) and the circle center and its radius .

How to make a collisionfree alogrithm to check whether the line segment passes through the circle or not.

I am asking this for the RRT (rapidly exploring random trees) algorithm.

Image Analyst
on 10 Oct 2020

See attached point-line distance demo.

Basically you need to see if the distance of the circle center to the line is less than the circle radius. If it is, there is an intersection. The code will show you how to do that.

Image Analyst
on 18 Oct 2020

Using the right math, you can determine if the line from the point perpendicular to the infinite line intersects the line in the segments where you defined the line. So if (xi,yi) is the intersection point of the perpendicular line with the infinite line, and (x1,y1) and (x2,y2) are the segment endpoints, it seems like you could just do

isInsideSegment = (x1<xi) && (xi<x2) && (y1<yi) && (yi<y2);

Right? Does that make sense?

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 2 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609876-what-is-a-good-algorithm-to-use-to-check-whether-the-finite-line-segment-intersects-the-circle#comment_1049501

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609876-what-is-a-good-algorithm-to-use-to-check-whether-the-finite-line-segment-intersects-the-circle#comment_1049501

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609876-what-is-a-good-algorithm-to-use-to-check-whether-the-finite-line-segment-intersects-the-circle#comment_1049546

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/609876-what-is-a-good-algorithm-to-use-to-check-whether-the-finite-line-segment-intersects-the-circle#comment_1049546

Sign in to comment.