## How to return the intersection point of a line and a circle-arc ?

### bh dhouha (view profile)

on 11 May 2015
Latest activity Commented on by John D'Errico

### John D'Errico (view profile)

on 11 May 2015
As shown in the figure below i would like to find the intersection between the edge and the arc Please help me

on 11 May 2015
How are you plotting it as an arc if it has just 3 points?
Presumably Matlab is adding more points to it if you are calling some built-in function to plot it otherwise you would just get straight lines between the points.
So your arc object should have 'XData' and 'YData' that are more than just 3 points I assume.
bh dhouha

### bh dhouha (view profile)

on 11 May 2015

on 11 May 2015
That function has an output argument which represents the arc object. Try something more like
hArc = drawCircleArc(...);
Then query
hArc.XData
hArc.YData
and they should have a lot more points to work with.
The equation of the line is trivial so even a for loop of the arc's XData testing the YData against the y-value of the line for the given x-value should give you the point on the arc which is closes to the line.
Then it is up to you what level of accuracy you want to home in from there to the true intersection value.

### John D'Errico (view profile)

on 11 May 2015
Edited by John D'Errico

### John D'Errico (view profile)

on 11 May 2015

Simplest is to turn them into a pair of polygons, then use Doug Schwarz's intersections tool from the file exchange. Just generate sufficiently many points on the circular arc, and it will be accurate.
If you want an exact or symbolic solution, then this too is doable. Not even that difficult. Simply formulate the equations of a circle and a line, then use solve.
syms x y t x1 x2 y1 y2 x0 y0 r theta
linex = (1-t)*x1 + t*x2;
liney = (1-t)*y1 + t*y2;
circlex = r*cos(theta) + x0;
circley = r*sin(theta) + y0;
[t,theta] = solve(linex == circlex,liney == circley,{t,theta});
Substitute in the values of {x0,y0,r,x1,x2,y1,y2}. If t is between 0 and 1, and theta is in the appropriate interval, then you have an intersection.
Or you could do it using fsolve, or pencil and paper.

bh dhouha

### bh dhouha (view profile)

on 11 May 2015
Thanks for the answer.Well i forgot to mention that the line is given by the two points and the circle arc is given by three points(center and two).Can't i find the intersection by just giving these points
Walter Roberson

### Walter Roberson (view profile)

on 11 May 2015
r would be the distance from the center to one of the other two points. If the distance to the other point is different than you are not dealing with a circle. x0 and y0 would be the center of the circle.
John D'Errico

### John D'Errico (view profile)

on 11 May 2015
I showed you what to do for a line based on two points. As far s a circle goes, as Walter points out, surely you can compute the radius of a circle given the center and one point on the circumference. with both points, as long as they are both the same distance from the center, that merely gives you a pair of angles. Just simple algebra.