
How to get the intersection points ??
조회 수: 20 (최근 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!