0

Possible Duplicate:
line and circle intersection

How will I find the intersection point of this circle and the line. I have used lincirc command in matlab with slope and intercept but it shows the point even if it wont exactly cross the circle. I want to get only the crossing two points. If the line cross one point, I want exactly the one crossing point. I don't want the point the point in the trajectory of that line. Thanks

Community
  • 1
  • 1
Justin Oommen
  • 13
  • 1
  • 7
  • How do you represent your line and circle in MATLAB? If they are represented by parametric equations, isn't it just to solve two equations with two unknowns? The solutions will be the intersection points. – chaohuang Jul 15 '12 at 20:34
  • I have a circle (x-a)^2 +(y-b)^2=r^2 and I have a random line say (x1,y1) and (x2,y2) which change for each simulation. I have used the polyfit fuction to calculate the slope and intercept and I used lincirc function, but it shows the two points even if the line crosses one point. Is there any other way to do it?? – Justin Oommen Jul 15 '12 at 20:49
  • I think your approach is right. Just aware that when the line is tangent to the circle, `linecirc` will return two identical points. – chaohuang Jul 15 '12 at 21:01
  • yes. The problem is, if the line crosses one side of the circle and stops inside the circle, it shows the other point where the line crosses if it is extended. Is there any other way to discard that point? – Justin Oommen Jul 15 '12 at 21:05
  • All you need to do is to check if the x-coordinate or y-coordinate of the intersection point lies in `[x1, x2]` or `[y1,y2]` (when slope is inf) – chaohuang Jul 15 '12 at 21:09
  • I couldn't get. how will I discard the point which wont cross? I'm able to get [x1,x2] and [y1,y2] but, In some cases only one point intersection will be there (not the case of tangent). how to deal with it? – Justin Oommen Jul 15 '12 at 21:16
  • `linecirc` gives you 2 intersection points, but the line segment between (x1,y1) and (x2,y2) could intersect the circle 0,1,2 times. Then you need to check the coordinates of the 2 returned intersection points. If the x-coordinate of a intersection point lies in [x1, x2], then the line segment cross the circle at this point. Otherwise, discard the point. (check the y-coordinate if the line slope is inf) – chaohuang Jul 15 '12 at 21:28

0 Answers0