How to determine if a vertical line segment intersects a circle?
This is a programming homework assignment, of which I have no qualms about doing it myself however I'm quite stuck on the geometry of it. I nee开发者_运维问答d to be able to determine the exact point of intersection given the center and radius of a circle and two end points of a vertical line segment, and since geometry isn't my forte I was hoping for some help (even pointers in the right direction would be appreciated!)
This probably isn't the best place to ask a question like this but I'm not really sure where else to look for help, my apologies if it's against the rules or something.
edit:
My apologies, what I am really having trouble with is determining what the points of intersection are (and if there is one intersection or two.) I've tried each solution given and they work great for determining if there is an intersection or not but my problem still persists as I mis-worded my question. If anyone can help with that it'd be much appreciated!
Try http://mathworld.wolfram.com/Circle-LineIntersection.html, this covers the geometry aspect of your problem quite well.
If C=(x0,y0) is the center, r the radius, and k the abscissa of the line, you have y = y0 +/- sqrt(r^2-(k-x0)^2), but no intersection if r < abs(k-x0)
using the centre [x,y] of the circle, find the distance of this particular line from the centre.refer now if this distance is > radius of the circle => the line won't intersect. otherwise, it will.
精彩评论