How to check the intersection of the line with a circle?
2 views (last 30 days)
Show older comments
I have a line with points A[5,60] and B[60,60]. Also I have 10 circles with x and y positions which is shown in matrix C below, the radius of each circle is r=1:
C= [46.5816 21.1706
29.2028 24.7608
23.8874 15.4974
19.3820 66.0560
36.2145 57.9523
14.4454 90.1348
34.2785 59.8094
37.0270 99.0752
49.1183 68.0090
31.6019 30.9405];
So, How Can I check that any circle's radius intersects with the given line? And I need to put condition that If any circle intersects with line, cancel that circle from the matrix C.
I plot lines and circles as shown in Figure below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154628/image.png)
According to the figure we can see that the circle (34.2785 59.8094)was intersected with line AB, so I need to cancel that point from the matrix C, and the results should be like that: C=
46.5816 21.1706
29.2028 24.7608
23.8874 15.4974
19.3820 66.0560
36.2145 57.9523
14.4454 90.1348
37.0270 99.0752
49.1183 68.0090
31.6019 30.9405
I used these code to plot 10 circles:
r=1; % radius of circles
th = linspace(0,2*pi) ;
x = r*cos(th) ;
y = r*sin(th) ;
% Loop for each circle
for i = 1:10 %10 is number of circles
xc = C(i,1)+x ;
yc = C(i,2)+y ;
hold on
plot(xc,yc) ;
end
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!