https://github.com/pgdr/tangent_lines_to_two_unit_circles
https://github.com/pgdr/tangent_lines_to_two_unit_circles
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/pgdr/tangent_lines_to_two_unit_circles
- Owner: pgdr
- Created: 2026-03-03T12:58:03.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2026-03-03T14:33:21.000Z (3 months ago)
- Last Synced: 2026-03-03T16:57:41.750Z (3 months ago)
- Language: Python
- Size: 51.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Inner tangent line for two unit circle placed with centers at y = 0 and one in origo
This script computes the tangent point (and corresponding angle) for the inner tangent line of two
unit circles: one centered at $(0,0)$ and one centered at $(d,0)$.
One can find the tangent line by imagining a rectangle placed with
bottom left at $(0,0)$ (origo) and height 2, with unknown length.
## Tangent line
[](https://github.com/pgdr/tangent_lines_to_two_unit_circles/raw/refs/heads/master/assets/tangent.mp4)

Then rotate the rectangle around origo until the top side hits $(d,0)$.
This results in a triangle with hypothenus $d$, one leg has side $2$,
which gives (soh-**cah**-toa) $\cos(\theta) = 2/d$ and thus
$$\theta = \arccos(2/d).$$

Then, given $\theta$, we can find the tangent point on the first
(left-most) unit circle as simply the unit vector with given
angle. Here we piggy-back on the complex class in Python to find the
coordinates (real=x, imag=y), using `cmath.rect(r, theta)`.
## Usage
```bash
python tangent.py
````
Example:
```bash
$ python tangent.py 5
```
outputs
```
tangent at (0.4, 0.917)
θ = 66.422°
Δ = ((0, 0), (0.4, 0.917), (2.5, 0))
```
The script prints:
* the tangent point on the left circle,
* $\theta$ in degrees,
* and a small helper triangle `Δ` for inspection.
## Code
```python
import math, cmath
def tangent_angle(d):
theta = math.acos(2 / d)
return theta
d = 5.0
theta = tangent_angle(d)
c = cmath.rect(1, theta)
print(f"tangent at {(c.real),(c.imag)}")
print(f"θ = {math.degrees(theta)}°")
print(f"Δ = ((0,0), {(c.real),(c.imag)}, {(d/2), 0})")
```
## Animation
