# Tangent to a Circle From a Distant Point

## Helper tool in geometry creation

Posted by Sourabh Bhat on June 28, 2019
Fig 1: Schematic diagram of the problem.
r :
xo :
yo :
xp :
yp :

Inputs:
Angles:
Tangent locations:

Recently, I was working with a friend on a problem requiring CFD simulation. To do the simulation, we needed to recreate a geometry from a research paper. It was a simple axi-symmetric geometry, a part of which is shown below.

Fig 2: Partial geometry from the research paper.

This is a fully defined geometry and we could have easily created it using a geometric software such as Solidworks or Catia, by applying necessary constraints of tangency. But we were working with Ansys ICEM meshing software. We knew the position of the center of the circle, its radius and the point at which the ramp begun. Here, I have indicated them as point $$O$$ and point $$P$$ respectively. If only we knew where the tangent touches the circle (Point $$T$$), or the angle at which the radial line touches the tangent (angle $$\theta$$), we could draw the line from point $$P$$ to point $$T$$.

This problem seems straightforward at first glance, and we thought so as well. But, it is difficult to solve it without an iterative approach. So, I developed a tool written in JavaScript and HTML (shown above) to do exactly that and provide the solution. I am putting it here, in hope that it would be useful to someone. For technical details on how the tool works continue to read below.

## How does it work?

A tangent line to a circle has a property that it is perpendicular to the radial line at the point of intersection. That is, line $$OT$$ is perpendicular to line $$TP$$. Which means that if we represent these lines as vectors, then the dot product of the two vector has to be zero (property of the dot product that is very very important and used way too often). The two vectors are created by joining $$T$$-$$P$$ and $$O$$-$$T$$. Mathematically, they are obtained by subtracting the coordinates of point $$P$$ from point $$T$$ and subtracting coordinates of point $$T$$ from point $$O$$. So we obtain the following vector equation:

$$\overrightarrow{OT}=\left[\begin{array}{c} r\,\cos\left(\theta\right)\\ r\,\sin\left(\theta\right) \end{array}\right]$$ and, $$\overrightarrow{TP} = \overrightarrow{P}-\overrightarrow{T}$$ $$\overrightarrow{TP} = \overrightarrow{P}-\left(\overrightarrow{O}+\overrightarrow{OT}\right)$$

The dot product between the two vectors is zero,

$$\overrightarrow{OT}\bullet\overrightarrow{TP} = 0$$ $$\overrightarrow{OT}\bullet\left(\overrightarrow{P}-\left(\overrightarrow{O}+\overrightarrow{OT}\right)\right) = 0$$

Writing it more explicitly, we get,

$$\left[\begin{array}{c} r\,\cos\left(\theta\right)\\ r\,\sin\left(\theta\right) \end{array}\right]\bullet\left[\begin{array}{c} x_{P}-x_{O}-r\,\cos\left(\theta\right)\\ y_{P}-y_{O}-r\,\sin\left(\theta\right) \end{array}\right]=0$$ which gives us the equation, $$r\,\cos\left(\theta\right)\,\left(x_{P}-x_{O}-r\,\cos\left(\theta\right)\right) +r\,\sin\left(\theta\right)\,\left(y_{P}-y_{O}-r\,\sin\left(\theta\right)\right)=0$$ and can be simplified to, $$\left(x_{O}-x_{P}\right)\,\cos\left({\color{blue}\theta}\right) +\left(y_{O}-y_{P}\right)\,\sin\left({\color{blue}\theta}\right)+r=0$$

As it is obvious we can have two solutions to this problem, or no solutions if the point lies inside the circle. The first solution can be obtained by using the Newton-Raphson method and initializing the iteration such that it converges to one of the sides. The second solution can be similarly obtained. The code decides if there is no solution if it is unable to converge within 100 iterations.

Interestingly, "Bintang ASWAM" has worked out two different ways of calculating analytical solutions to angles and tangent points. The solutions are available at: Solutions.

So now that you know how it works go ahead and use the tool whenever you need it. Feel free to write to me if it is useful or if you find any bugs.

Thanks for using this tool… :)

Watch the video below for an animated treat.