2

Possible Duplicate:
Circle line collision detection

I have a problem. I need to find point A. enter image description here

How can I do this best way?

Programming languale is Java.

7
  • 2
    Programming language doesn't matter. This is basic maths. Commented Oct 21, 2012 at 20:30
  • 1
    This is not a java-specific question, it is pure math. Commented Oct 21, 2012 at 20:30
  • Yes, but if anyone has a solution to this programming language, it can share it without any additional explanations. Commented Oct 21, 2012 at 20:31
  • Is this do my homework question? Commented Oct 21, 2012 at 20:32
  • No, it's my 'I want to finish my project' question. Commented Oct 21, 2012 at 20:33

1 Answer 1

4

Given: a circle with center C=[x2,y2] and radius R a line segment from C to B=[x1,y2] calculate their intersection.

This is easy since one of the endpoints is the center of the circle. You have to walk the distance of R from C towards B. The distance guarantees you will end up on the circle and the direction guarantees you will end up on the ray C->B. You still need to check if the intersection lies on the segment.

Here is the pseudocode if you have a vector library

- offset = B-C - if length_square(offset) < R^2 output "no intersection" - offset_a = normalize(B-C) * R - output C + offset_a 

Without a library, the code is longer:

- off_x = x1-x2; - off_y = y1-y2; - ls = off_x*off_x + off_y*off_y - if ls < R*R -- return an empty array, meaning "no intersections" - scale = R / sqrt(ls) - res_x = off_x * scale + x2 - res_y = off_y * scale + y2 - return [[off_x, off_y]] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.