# distance to arc as function of angle

I'm having trouble with a geometry problem:

I have two circles concentric on the origin, M, of radii R and r, where R > r.

Choosing a fixed point Q on the inner circle circumference, and a point P on the outer circle circumference, I want to find the distance of QP (call it d) as a function of angle, a (and r and R), as P moves once around the outer circle circumference, where a is the angle made between the positive x-axis and the line QP.

I started by letting Q = (-r,0). A triangle MPQ is formed by the two points and the origin, with sides d, R, and r.

Let b be the angle made between the positive x-axis and MP. Then the distance d can be found as a function of b:

$d = \sqrt{(R\cos(b))^2 + (R\sin(b)+r)^2}$, for $b = 0 \text{ to } 360$

Now I want to change the parameter b for the angle a.

I thought about using the sine / cosine rule next on the triangle MPQ, but can't seem to solve it.

Apply the cosine rule to triangle $QMP$: $$PM^2=QM^2+QP^2-2QM\cdot QP\cos a,$$ that is: $$R^2=r^2+d^2-2rd\cos a.$$ You can now solve for d: $$d=r\cos a\pm\sqrt{R^2-r^2\sin^2 a}.$$
$$d^2 = R^2 + r^2 - 2 R r \cos b$$
$$\tan {a} =\dfrac {R\sin b } { R\cos b - d \cos \alpha}$$