Jump to content
  • Advertisement
Sign in to follow this  
Xabier Otano

Line & Circle Intersetcion

This topic is 1880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!