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:
Doesn anyone know how to do that?
Answer
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.
No comments:
Post a Comment