tags:

views:

66

answers:

4

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 need 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!

A: 

Try http://mathworld.wolfram.com/Circle-LineIntersection.html, this covers the geometry aspect of your problem quite well.

Greg Sexton
Greg Sexton: This looks very much like what I need but my problem that I have with it perhaps is that I'm not very good at math. If the discriminant > 0 does that mean there is always two intersections? I don't think that is the case but as is I'm not sure how to determine the correct point of intersection in that case. Maybe I just need to look at it some more, but it certainly very easily answers my original question so thank you - but unfortunately I forgot to add the part that was actually troubling me in the original question. Thanks for the link though!
Joe.F
A: 

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)

enzotib
enzotib: I apologize but I honestly don't understand what you mean by x0,y0 - are they meant as subscripts starting at 0? I'm used to subscripts starting at 1 in math but I know they start at 0 in most programming languages so it may be a silly question. Also, the abscissa is the x coordinate in a (x,y) coordinate pair correct? I looked it up and that appears to be right but I'm not really sure. Anyway, this answers my original question so thank you but unfortunately I forgot to also include that I need to be able to determine the points of intersection.
Joe.F
x0, y0 are simply names for the two coordinates of the center of the circle
enzotib
A: 

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.

anirvan
anirvan-majumdar: I apologize this isn't the solution I was seeking, although it answers my original question. Thank you for the response though!
Joe.F
A: 

Someone else has already asked this question on StackOverflow. Here is the link, for reference: http://stackoverflow.com/questions/1073336/circle-line-collision-detection

Ari Patrick
Ari Patrick: Thanks, I've been reading through it but honestly it's a bit above my level of comprehension. I'm having trouble picking out what is the relevant information as I'm only interested in vertical line segments (which to my understanding are generally considered special case in this problem?) I may be wrong though, but thanks anyway!
Joe.F