フィルターのクリア

How to check the intersection of the line with a circle?

5 ビュー (過去 30 日間)
Beibit Sautbek
Beibit Sautbek 2016 年 7 月 1 日
編集済み: Thorsten 2016 年 7 月 1 日
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:
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

採用された回答

Thorsten
Thorsten 2016 年 7 月 1 日
編集済み: Thorsten 2016 年 7 月 1 日
For a horizontal line, you just have to check if the y position of the circle is closer to the line than the radius:
idx = abs(C(:,2) - 60) < 1
And to remove that circle, use
C(idx, :) = [];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by