MATLAB: Intersection between line and circle when line ends inside circle (using geom2d)

circlegeom2dlineMATLAB

I have a circle and a line drawn like so…
Image 1.png
Using the createLine function in the geom2d collection, the line is treated like this (i.e. continuous)…
Image 2.png
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.

Best Answer

  • Someone should copy their comment to the answers section so it can be accepted.
It should be me
% 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)