
How to get the intersection points ??
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Image Analyst
el 1 de Feb. de 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??
Respuesta aceptada
Matt J
el 17 de Ag. de 2018
Editada: Matt J
el 17 de Ag. de 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 comentarios
Matt J
el 18 de Ag. de 2018
This will give you a map of where the non-empty P{i,j} lie
map=~cellfun('isempty',P)
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!