How to get the intersection points ??

21 ビュー (過去 30 日間)
Eman S
Eman S 2018 年 8 月 17 日
編集済み: Eman S 2020 年 2 月 2 日
Hi all, I have the following code to get the intersection points between these multiple lines and these multiple circles.
%%center of circles
X = [0.02 0.44; 0.08 0.58 ;...
0.22 0.57; 0.3 0.9; ...
0.44 0.79; 0.35 0.318;...
0.54 0.29; 0.95 0.11;...
0.93 0.7; 0.82 0.93];
C_M=[X(:,1) X(:,2)];
hold on
%%Assign labels to the points.
Assign_labels_to_all_points ( X ,X(:,1),X(:,2))
hold on
%%Draw circles
theta = linspace(0,2*pi) ;
x = 0.15*cos(theta) ; y =0.15*sin(theta) ;
C_M=[X(:,1),X(:,2)];
deg = 0 : 2.5 : 90;
for i=1:length(deg)
r =2;
x_ax = r*[zeros(size(deg(i))) cosd(deg(i))];
y_ax = r*[zeros(size(deg(i))) sind(deg(i))];
%%plot lines with different angles
plot(x_ax, y_ax, 'LineWidth',1.3)
for index = 1:length(C_M)
if ~isinf(C_M(index))
xx = x+C_M(index,1);
yy = y+C_M(index,2);
%%plot circles
plot(xx,yy,'-b','linewidth',1.5)
for j=1:length(deg)
P = InterX([x+C_M(index,1);y+C_M(index,2)],[r*[zeros(size(deg(j))) cosd(deg(j))];r*
[zeros(size(deg(j))) sind(deg(j))]]);
%%plot intersection points between lines and circles
plot(P(1,:),P(2,:),'or');
end
end
end
end
%%x and y axis limits
xlim([-0.2,1.2])
ylim([-0.2,1.2])
grid on
grid minor
I used the file exchange function InterX. It only draws the intersection points as the following image. But, I can't get these intersection points to store them in matrix or array.
So, my question is: How to get the intersection points between each line and the circles that intersected with that line and store them in array or matrix?? Any suggestions to modify this code??
  1 件のコメント
Image Analyst
Image Analyst 2020 年 2 月 1 日
Original question (in case he delete this one also):
How to get the intersection points between (each line and the circles that intersected with that line)??
Hi all, I have the following code to get the intersection points between these multiple lines and these multiple circles.
%%center of circles
X = [0.02 0.44; 0.08 0.58 ;...
0.22 0.57; 0.3 0.9; ...
0.44 0.79; 0.35 0.318;...
0.54 0.29; 0.95 0.11;...
0.93 0.7; 0.82 0.93];
C_M=[X(:,1) X(:,2)];
hold on
%%Assign labels to the points.
Assign_labels_to_all_points ( X ,X(:,1),X(:,2))
hold on
%%Draw circles
theta = linspace(0,2*pi) ;
x = 0.15*cos(theta) ; y =0.15*sin(theta) ;
C_M=[X(:,1),X(:,2)];
deg = 0 : 2.5 : 90;
for i=1:length(deg)
r =2;
x_ax = r*[zeros(size(deg(i))) cosd(deg(i))];
y_ax = r*[zeros(size(deg(i))) sind(deg(i))];
%%plot lines with different angles
plot(x_ax, y_ax, 'LineWidth',1.3)
for index = 1:length(C_M)
if ~isinf(C_M(index))
xx = x+C_M(index,1);
yy = y+C_M(index,2);
%%plot circles
plot(xx,yy,'-b','linewidth',1.5)
for j=1:length(deg)
P = InterX([x+C_M(index,1);y+C_M(index,2)],[r*[zeros(size(deg(j))) cosd(deg(j))];r*
[zeros(size(deg(j))) sind(deg(j))]]);
%%plot intersection points between lines and circles
plot(P(1,:),P(2,:),'or');
end
end
end
end
%%x and y axis limits
xlim([-0.2,1.2])
ylim([-0.2,1.2])
grid on
grid minor
I used the file exchange function InterX. It only draws the intersection points as the following image. But, I can't get these intersection points to store them in matrix or array.
So, my question is: How to get the intersection points between each line and the circles that intersected with that line and store them in array or matrix?? Any suggestions to modify this code??

サインインしてコメントする。

採用された回答

Matt J
Matt J 2018 年 8 月 17 日
編集済み: Matt J 2018 年 8 月 17 日
Can't you just modify as follows,
P{i,j} = InterX([x+C_M(index,1);y+C_M(index,2)],[r*[zeros(size(deg(j))) cosd(deg(j))];r*
[zeros(size(deg(j))) sind(deg(j))]]);
%%plot intersection points between lines and circles
plot(P{i,j}(1,:),P{i,j}(2,:),'or');
  6 件のコメント
Matt J
Matt J 2018 年 8 月 18 日
This will give you a map of where the non-empty P{i,j} lie
map=~cellfun('isempty',P)
Eman S
Eman S 2018 年 8 月 18 日
編集済み: Eman S 2018 年 8 月 18 日
Thanks so much for your reply and your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by