Find a line along a circle's perimeter?

108 Views Asked by At

If I know coordinates of point $A$, coordinates of circle center $B$ and r as the radius of the circle, is it possible to calculate lines that are passing through point $A$ that are also tangent to the circle?

Example of result

A is the green point, B is the center of the red circle and I am trying to find out the blue lines.

1

There are 1 best solutions below

0
On BEST ANSWER

Denote coordinates of point $A$ with $(x_A, y_A)$ and center B with $(x_B, y_B)$. Suppose that tangent AT touches circle at point $T$ with coordinates $(x_T,y_T)$.

You have:

$$AB=\sqrt{(x_B-x_A)^2+(y_B-y_A)^2}\tag{1}$$

$$AT=\sqrt{AB^2-r^2}\tag{2}$$

Denote the angle between line AB and $x$-axis with $\alpha$ and the angle $\angle TAB$ with $\beta$. You can calculate the value of $\alpha$ from:

$$\alpha=\arctan\frac{y_B-y_A}{x_B-x_A}\tag{3}$$

...and the angle $\beta$ from the right triangle $\triangle ATB$:

$$\beta=\arcsin\frac{r}{AB}\tag{4}$$

Note that the solution exists only if (2) makes sense ($AB\ge r$). And if you are using computers to do the calculation, you should always use function like $atan2$ to compute $\alpha$ from the right quadrant.

Coordinates of point T can be obtained from the following expressions:

$$x_T=x_A+AT \space \cos(\alpha \pm\beta)$$

$$y_T=y_A+ AT \space \sin(\alpha \pm\beta)$$

In general, you have two different solutions for $AB>r$ and only one, trivial, for $AB=r$ ($T\equiv A$).

Equations of tangents are:

$$y-y_A=(x-x_A)\tan(\alpha\pm\beta)$$