
How to get the intersection points ??
16 次查看(过去 30 天)
显示 更早的评论
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
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
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
2018-8-18
This will give you a map of where the non-empty P{i,j} lie
map=~cellfun('isempty',P)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!