Skip to main content
16 events
when toggle format what by license comment
Sep 14, 2021 at 21:35 comment added Gareth Rees @Paulo The points of intersection are \$ p_1 + t_1v \$ and \$ p_1 + t_2v \$.
Aug 24, 2021 at 16:55 comment added Paulo How to get the points of intersections of the circle and the line, if the line is intersecting the circle?
Oct 17, 2015 at 12:31 history edited Gareth Rees CC BY-SA 3.0
in Python 2, need floating-point division
Oct 15, 2015 at 20:43 review Suggested edits
Oct 15, 2015 at 22:10
Apr 9, 2015 at 22:18 comment added Gareth Rees @TochiObudulu: \$ t_1 + t_2 \over 2 \$ is the same as \$ -b \over 2a \$: it gives the point on the extended line that's closest to the centre of the circle. But it is not necessarily on the line segment itself. If this matters for your application, then you need to clamp it. (I don't know exactly what is involved in "moving them away from each other" so I can't be sure what is the right result.)
Apr 9, 2015 at 22:14 comment added Tochi Obudulu @GarrethRoss: Ahh, - works fine now. Just out of interest, in my case, would it be less expensive to use (t1+t2)/2 or the clamps that you suggested or does the mid-point approach not always yield the right result?
Apr 9, 2015 at 22:10 vote accept Tochi Obudulu
Apr 9, 2015 at 21:28 history edited 200_success CC BY-SA 3.0
added 96 characters in body
Apr 9, 2015 at 21:16 comment added Gareth Rees @TochiObudulu: I made a sign error in the final calculation of \$ t \$: it needs to be \$ -b \over 2a \$. Now fixed. Sorry about that!
Apr 9, 2015 at 21:14 history edited Gareth Rees CC BY-SA 3.0
fix sign error
Apr 9, 2015 at 20:59 comment added Tochi Obudulu Thanks for the answer (and concise explanation). Your code pretty much functioned as you said expect that it was returning either point 1 or point 2 upon collision. What I meant by 'the closest point' was the closest point that lay on the line segment. The value of t for this solution is essentially the midpoint of the two scalar parameters: (t2+t1)/2 the significance of this is mainly that the output of the function is used to separate (constrain) the circle and line segment by moving them away from each other such that the line segment is at a perfect tangent to the circle.
Apr 9, 2015 at 19:03 history edited Gareth Rees CC BY-SA 3.0
reuse a and b in the computation of t
Apr 9, 2015 at 18:49 history edited Gareth Rees CC BY-SA 3.0
Fix closest point calculation
Apr 9, 2015 at 18:39 history edited Gareth Rees CC BY-SA 3.0
link to demo
Apr 9, 2015 at 18:31 history edited Gareth Rees CC BY-SA 3.0
return the result that seems to be needed by the OP — closest point to centre of circle
Apr 9, 2015 at 17:56 history answered Gareth Rees CC BY-SA 3.0