Intersection between line and circle when line ends inside circle (using geom2d)
Ältere Kommentare anzeigen
I have a circle and a line drawn like so...

Using the createLine function in the geom2d collection, the line is treated like this (i.e. continuous)...

Therefore, when finding the intersection points between the line and the circle, two points are returned instead of one.
How can I solve this problem of showing an extra incorrect point, and is there a workaround you could suggest, either using geom2d or otherwise?
Many thanks.
8 Kommentare
darova
am 20 Nov. 2019
John D
am 20 Nov. 2019
darova
am 20 Nov. 2019
Yes it will
John D
am 21 Nov. 2019
darova
am 21 Nov. 2019
Provide experimental data
John D
am 21 Nov. 2019
% Position of line:
x1 = [0.1947
0.5173];
y1 = [0.4388
0.5933];
% Center point of circle:
x0 = 0.4850;
y0 = 0.6239;
% Radius of circle:
r = 0.2035;
t = linspace(0,2*pi,30);
x2 = r*cos(t) + x0;
y2 = r*sin(t) + y0;
[xc,yc] = polyxpoly(x1,y1,x2,y2)
Adam Danz
am 21 Nov. 2019
To demonstrate both methods,
% Define circle
ang=0:0.1:2*pi;
xyr = [5 2 4]; %(xCenter,yCenter,radius)
xp=xyr(:,3)*cos(ang) + repmat(xyr(:,1),1,numel(ang)); %changed 190901 to work with r2016a
yp=xyr(:,3)*sin(ang) + repmat(xyr(:,2),1,numel(ang));
% Define line endpoints
xln = [1 6];
yln = [-1 1];
% plot it
clf()
plot(xp,yp,'k-') %circle
axis equal; grid on; hold on
plot(xln,yln,'b-') %line
% Method 1 uses this FEX:
% https://www.mathworks.com/matlabcentral/fileexchange/11837-fast-and-robust-curve-intersections
[x0,y0] = intersections(xp,yp,xln,yln);
plot(x0,y0,'r*','MarkerSize',9,'LineWidth',2) %intersection point(s)
% Method 2
[xi,yi] = polyxpoly(xp,yp,xln,yln);
plot(xi,yi,'gh','MarkerSize',15,'LineWidth',2) %intersection point(s)

Someone should copy their comment to the answers section so it can be accepted.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Geographic Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!