0

I am trying to detect the intersection of a circle with a line and work out the one (tangent) or two (secant) points on the line where the intersection occurs. I want to exclude intersections which are not between the two points which define the line.

There are many solutions on the internet, videos, SO posts, which all provide very good answers to the base of this question, but I can't find anything which includes "intersections only between the line end points".

My best reference so far is: Circle line-segment collision detection algorithm? However, as I mention, implementing this returns intersections which are anywhere on the vector, not just the on particular line specified, between it's ends.

To explain: If the circle in this diagram were to intersect the line, I am only looking for intersections which occur between points A and B, not outside.

enter image description here

Community
  • 1
  • 1
Matt W
  • 11,753
  • 25
  • 118
  • 215
  • A line may intersect with a circle in: 0 points, 1 point, or 2 points. Are you looking for line equation?, points coordinates? What do you want exactly? Why not post a picture? – NoChance Oct 11 '15 at 08:36
  • The diagrams on the post I linked to explain it just as well as I could (and I'm no artist). The question is the same, too, but with the added condition that I don't want intersections on the line which don't occur between the two points being used to define the line. – Matt W Oct 11 '15 at 08:44
  • 1
    The answer from that question gives you exactly what you want - what may not be clear from the answer (it is very long) is that you should only accept the results it gives when *t* is between 0 and 1. (If it is exactly 0 or 1, that means the intersection is exactly at the endpoint of the line segment.) – psmears Oct 11 '15 at 08:46
  • The question seems to be exactly the same (a "line segment" **is** the part "between the two endpoints"). Do you mean one of the answers there do not work for you? How about the other answers? – Jongware Oct 11 '15 at 08:50
  • I think @psmears has told me what I must have been missing from the post I linked. And yes, I only want the intersections on the "line segment". – Matt W Oct 11 '15 at 08:54
  • Strangely, I never see t being between 0..1 - it is always much larger. For my scenario, >0 is just right, but it would be good to know what is the logic for defining 0..1 – Matt W Oct 11 '15 at 09:09
  • In fact, t is only 0..1 if I divide it by the length of A..B - so #win! – Matt W Oct 11 '15 at 09:12
  • Possible duplicate of [Circle line-segment collision detection algorithm?](http://stackoverflow.com/questions/1073336/circle-line-segment-collision-detection-algorithm) – Jongware Oct 11 '15 at 09:26
  • I would agree that now - but originally I was looking for a more specific answer, not realising it was already there. – Matt W Oct 11 '15 at 09:27

0 Answers0