Sign in to follow this  
Followers 0
Xabier Otano

Line & Circle Intersetcion

2 posts in this topic

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
0

Share this post


Link to post
Share on other sites

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
2

Share this post


Link to post
Share on other sites

@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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0