2

I tried using a raycasting-style function to do it but can't get any maintainable results. I'm trying to calculate the intersection between two tangents on one circle. This picture should help explain:

enter image description here

I've googled + searched stackoverflow about this problem but can't find anything similar to this problem. Any help?

original_username
  • 2,398
  • 20
  • 24
Conros
  • 167
  • 1
  • 3
  • 7

2 Answers2

3

Well, if your variables are:

C = (cx, cy) - Circle center
A = (x1, y1) - Tangent point 1
B = (x2, y2) - Tangent point 2

The lines from the circle center to the two points A and B are CA = A - C and CB = B - C respectively.

You know that a tangent is perpendicular to the line from the center. In 2D, to get a line perpendicular to a vector (x, y) you just take (y, -x) (or (-y, x))

So your two (parametric) tangent lines are:

L1(u) = A + u * (CA.y, -CA.x)
      = (A.x + u * CA.y, A.y - u * CA.x)

L2(v) = B + v * (CB.y, -CB.x)
      = (B.x + v * CB.y, B.x - v * CB.x)

Then to calculate the intersection of two lines you just need to use standard intersection tests.

Peter Alexander
  • 53,344
  • 14
  • 119
  • 168
1

The answer by Peter Alexander assumes that you know the center of the circle, which is not obvious from your figure http://oi54.tinypic.com/e6y62f.jpg. Here is a solution without knowing the center:

The point C (in your figure) is the intersection of the tangent at A(x, y) with the line L perpendicular to AB, cutting AB into halves. A parametric equation for the line L can be derived as follows:

The middle point of AB is M = ((x+x2)/2, (y+y2)/2), where B(x2, y2). The vector perpendicular to AB is N = (y2-y, x-x2). The vector equation of the line L is hence L(t) = M + t N, where t is a real number.

Jiri Kriz
  • 9,192
  • 3
  • 29
  • 36