A Belt Around Two Pulleys

Given two pulleys of radius (X) and (Y), and the distance (D) between
their centers, find the circumference (Z) of the belt which goes around
both pulleys. Assume the belt touches at least part of each pulley, and
the pulleys can overlap (D can be less than X+Y).

With the definitions as above, if you're given X, Y, and Z, find D.
Source: Reader David Quinn, though I wouldn't be surprised to hear of
other sources.
Solutions were received from
Nick McGrath, Allan Christensen, Sudipta Das, Philippe Fondanaiche,
Jozef Hanenberg, and Paul Botham. All solvers found a solution for
part 1 and pointed out that part 2 was either impossible or had to be
solved by approximations. Thanks to Sudipta Das
for mentioning a
similar problem
at the SMSU problem corner.
Paul Botham's solutions are quite succinct, yet not difficult to
understand their derivation:
1. Z in terms of X, Y, D
====
Assume Y > X (or Y = X)
Let A be the angle each straight section of belt makes to horizontal
Then:
Z = 2 * D * COS[A] + PI * (X+Y) + 2 * (YX) * A
where SIN[A] = (YX) / D
PI = 3.141...
2. D in terms of X, Y, Z
====
[Z  PI * (X+Y)] / [2 * (YX) ] = COT[A] + A
solve numerically for A
then D = (YX) / SIN[A]
Mail to Ken