Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Common Tangent

  Find common tangent lines of two circles $c1$ and $c2$.

Input

Center coordinates ($cix$, $ciy$) and radii $cir$ of two circles $c1$ are $c2$ are given in the following format.

$c1x \; c1y \; c1r$ 

$c2x \; c2y \; c2r$

All input values are given in integers.

Output

  Print coordinates of the tangent points on circle $c1$ based on the following rules.

  
Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.
  

  The output values should be in a decimal fraction with an error less than 0.00001.

Constraints

$-1,000 \leq c1x, c1y, c2x, c2y \leq 1,000$

$1 \leq c1r, c2r \leq 1,000$

$c1$ and $c2$ are different

Sample Input 1

1 1 1
6 2 2

Sample Output 1

0.6153846154 1.9230769231
1.0000000000 0.0000000000
1.4183420913 1.9082895434
1.7355040625 0.3224796874

Sample Input 2

1 2 1
4 2 2

Sample Output 2

0.6666666667 1.0571909584
0.6666666667 2.9428090416
2.0000000000 2.0000000000

Sample Input 3

1 2 1
3 2 2

Sample Output 3

0.5000000000 1.1339745962
0.5000000000 2.8660254038

Sample Input 4

0 0 1
1 0 2

Sample Output 4

-1.0000000000 0.0000000000

Sample Input 5

0 0 1
0 0 2

Sample Output 5

No output.



Sample input:
1 1 1
6 2 2


Sample output:
0.6153846154 1.9230769231
1.0000000000 0.0000000000
1.4183420913 1.9082895434
1.7355040625 0.3224796874

Submission status: Accepted

Solution code:
from math import acos, atan2, cos, hypot, isclose, pi, sin
from typing import List, Tuple


def tangent_points(c1x: float, c1y: float, c1r: float,
                   c2x: float, c2y: float, c2r: float) -> List[Tuple[float, float]]:
    c1c2 = hypot(c2x - c1x, c2y - c1y)
    t0 = atan2(c2y - c1y, c2x - c1x)
    ps: List[Tuple[float, float]] = []

    r1r2 = c1r + c2r
    if isclose(c1c2, r1r2):
        ps.append((c1x + c1r * cos(t0), c1y + c1r * sin(t0)))
    elif c1c2 > r1r2:
        t1 = acos(r1r2 / c1c2)
        ps.append((c1x + c1r * cos(t0 + t1), c1y + c1r * sin(t0 + t1)))
        ps.append((c1x + c1r * cos(t0 - t1), c1y + c1r * sin(t0 - t1)))

    r1r2 = c1r - c2r
    if isclose(c1c2, abs(r1r2)):
        if r1r2 > 0.0:
            t1 = 0.0
        else:
            t1 = pi
        ps.append((c1x + c1r * cos(t0 + t1), c1y + c1r * sin(t0 + t1)))
    elif c1c2 > abs(r1r2):
        if r1r2 > 0.0:
            t1 = acos(r1r2 / c1c2)
        else:
            t1 = pi - acos(-r1r2 / c1c2)
        ps.append((c1x + c1r * cos(t0 + t1), c1y + c1r * sin(t0 + t1)))
        ps.append((c1x + c1r * cos(t0 - t1), c1y + c1r * sin(t0 - t1)))

    return ps


if __name__ == "__main__":
    c1x, c1y, c1r = map(lambda x: float(x), input().split())
    c2x, c2y, c2r = map(lambda x: float(x), input().split())

    ps = tangent_points(c1x, c1y, c1r, c2x, c2y, c2r)

    for p in sorted(ps):
        print("{:.6f} {:.6f}".format(*p))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# CGL_7_G: Circles - Common Tangent

from math import acos, atan2, cos, hypot, isclose, pi, sin


def tangent_points(circle1, circle2):
    x1, y1, r1 = circle1
    x2, y2, r2 = circle2

    c1c2 = hypot(x2-x1, y2-y1)
    t0 = atan2(y2-y1, x2-x1)
    ps = []

    r1r2 = r1+r2
    if isclose(c1c2, r1r2):
        ps.append((x1 + r1*cos(t0), y1 + r1*sin(t0)))
    elif c1c2 > r1r2:
        t1 = acos(r1r2 / c1c2)
        ps.append((x1 + r1*cos(t0+t1), y1 + r1*sin(t0+t1)))
        ps.append((x1 + r1*cos(t0-t1), y1 + r1*sin(t0-t1)))

    r1r2 = r1-r2
    if isclose(c1c2, abs(r1r2)):
        if r1r2 > 0.0:
            t1 = 0.0
        else:
            t1 = pi
        ps.append((x1 + r1*cos(t0+t1), y1 + r1*sin(t0+t1)))
    elif c1c2 > abs(r1r2):
        if r1r2 > 0.0:
            t1 = acos(r1r2 / c1c2)
        else:
            t1 = pi - acos(-r1r2 / c1c2)
        ps.append((x1 + r1*cos(t0+t1), y1 + r1*sin(t0+t1)))
        ps.append((x1 + r1*cos(t0-t1), y1 + r1*sin(t0-t1)))

    return ps


def run():
    c1 = [int(i) for i in input().split()]
    c2 = [int(i) for i in input().split()]

    ps = tangent_points(c1, c2)

    for p in sorted(ps):
        print("{:.10f} {:.10f}".format(*map(eliminate_minus_zero, p)))


def eliminate_minus_zero(f):
    if isclose(f, 0.0, abs_tol=1e-9):
        return 0.0
    else:
        return f


if __name__ == '__main__':
    run()