- Someone should copy their comment to the answers section so it can be accepted.

7 views (last 30 days)

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.

darova
on 21 Nov 2019

- 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)

Adam Danz
on 21 Nov 2019

2 Changes you need to make.

1) you're not extracting the x and y coordinates of the line correctly.

% x1 = [h.Position(1) h.Position(3)]; wrong

% y1 = [h.Position(2) h.Position(4)]; wrong

x1 = h.Position(:,1);

y1 = h.Position(:,2);

2) This one is minor. As long as your ROI line and circle objects are still on the plot, new lines will be plotted under them. If you mark the intersection with a small marker, you won't see it.

% solution one: make the marker large

plot(xc, yc, 'ro','markersize',12)

% solution two: remove the cirlce ROI object and replace it with your

% computed circle

delete(c)

hold on

plot(x2,y2,'b-', 'LineWidth',4)

% Plot intersection point on top

plot(xc, yc, 'ro')

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769515

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769515

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769519

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769519

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769528

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769528

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769789

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769789

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769800

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769800

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769805

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769805

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769815

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769815

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769824

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/492196-intersection-between-line-and-circle-when-line-ends-inside-circle-using-geom2d#comment_769824

Sign in to comment.