How to get the intersection points ??
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Image Analyst
am 1 Feb. 2020
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??
Akzeptierte Antwort
Matt J
am 17 Aug. 2018
Bearbeitet: Matt J
am 17 Aug. 2018
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 Kommentare
Matt J
am 18 Aug. 2018
This will give you a map of where the non-empty P{i,j} lie
map=~cellfun('isempty',P)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!