• Create Account

## Line & Circle Intersetcion

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

101
Like
0Likes
Like

Posted 28 August 2013 - 08:14 AM

Hi there,

i am having so much troubles finding C++ code that tell me what is the point of intersection of a circle and a line that grows from its center.

I have a circle with center C and a point A  (is given by the touch of a person on the screen)

The line between C-A intersect with the circle in some place in the circle Z, i want to know how to calculate this Z(x,y) and if it possible a c++ solution will be awesome.

Has someone some useful code i can try?

SO many thanks mates

I have reades this web but when i translate the code i got some strange values , dunno why-

http://mathworld.wolfram.com/Circle-LineIntersection.html

As i said the only important point is the one which is isnide the circle AND is between the center C and the touch point A.

Edited by unadepipas, 28 August 2013 - 08:17 AM.

5832
Like
2Likes
Like

Posted 28 August 2013 - 08:28 AM

let c = (cx, cy) EDIT: That's the centre of the circle, should have mentioned that huh? lol

let touch point p = (px, py)

vector from c to p = p - c = (px - cx, py - cy), call this r.

intersect point = c + normalize( r ) * radius

You can also use trig, the angle in radians from the centre is atan2(ry, rx) but then you have to use trig again to find intersect point = (cx + radius * cos(angle), cy + radius * sin(angle)).

I'm guessing the mathworld link is for the generic case of line-circle intersection (i.e. line doesn't have to go through the centre so there are 0, 1 or 2 solutions).

Edited by Paradigm Shifter, 28 August 2013 - 08:46 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #3jjd  Members

2140
Like
0Likes
Like

Posted 28 August 2013 - 08:37 AM

@OP you say that A is outside the circle. Is the always the case? Could the user touch within the circle? What point do you want returned if they do?

-Josh

--www.physicaluncertainty.com