2
\$\begingroup\$

I'm trying to figure out how to calculate the following angle:

I know center (p1) and radius (r) of a circle. Given a point p3 I want to calculate the angle a such as the tangent (tan) of the circle at point p4, points in p3 direction.

Here's a figure:

enter image description here

Doesn anyone know how to do that?

\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

Let b be the angle between vectors p1p2 and p1p3. Its value can be computed as:

b = pi - atan2(p1p3.y, p1p3.x)

The angle between p1p4 and p1p3 is b-a. Since p1p3p4 is a right-angled triangle, we know that cos(b-a) is the distance p1p4 divided by the distance p1p3.

The answer is then:

a = pi - atan2(p1p3.y, p1p3.x) - acos(r / length(p1p3))

Replacing the second - with + will give you the second possible solution.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you very much. I google a lot searching answer to this, but I didn't find anything. Simple and clear solution!! \$\endgroup\$
    – Heisenbug
    Commented Sep 9, 2012 at 19:57
-1
\$\begingroup\$

I was going to calculate this, then I failed, then I googled, then I found people who failed multiple times as well. But in the end some seem to have gotten it right :).

Read this entire thread, it should lead you to the correct algorithm.

\$\endgroup\$
5
  • \$\begingroup\$ Why was this downvoted? Doesn't the link have the exact answer? Btw the search query was "tangent circle point". \$\endgroup\$
    – Roy T.
    Commented Sep 9, 2012 at 20:05
  • 2
    \$\begingroup\$ See: meta.stackexchange.com/questions/8231/… \$\endgroup\$
    – Eric
    Commented Sep 9, 2012 at 20:13
  • \$\begingroup\$ Hah didn't know that. You are absolutely right, I even agree after reading that topic. Well I guess I never did this before :P. \$\endgroup\$
    – Roy T.
    Commented Sep 9, 2012 at 20:15
  • \$\begingroup\$ Note that the thread in question seems to indicate that there are four possible answers. There must be something wrong there. \$\endgroup\$ Commented Sep 10, 2012 at 0:43
  • \$\begingroup\$ No there are 2 possible lines, but four possible vectors describing that line, hence the four solutions. \$\endgroup\$
    – Roy T.
    Commented Sep 10, 2012 at 6:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .