I've posted an image below of the task I'm trying to accomplish. I have a right triangle, $R + r, d, R$, where $R + r$ is the hypotenuse. Then, I draw another (dotted) line labeled $R'$ at an angle $\phi$ with respect to the hypotenuse that touches the x -axis. $X$ is the perpendicular line from the hypotenuse to $R'$, at a distance of $R$ down along the hypotenuse. $Y$ is the perpendicular distance from the origin to where $R'$ touches the x-axis. Basically, I want to derive a relation between $x$ and $y$ that uses all of the variables defined in the figure.

I believe derived a relation between the two, but I don't think it's right because it fails at $\phi = 0, \theta = 0$. I've used three relations: \begin{align}\tan(\phi) &= \frac{X}{R}\\ \tan(\phi + \theta) &= \frac{D}{R-H}\\ \tan\!\left(\frac{\pi}{2} - \theta - \phi\right) &= \frac{H}{Y} \end{align}
I've defined $H$ to be the vertical distance from the origin to where $R'$ intersects $R$. From these, I've derived the relation to be: $$ Y = \frac{\frac{X}{\tan(\phi)} - \frac{D}{\tan(\phi + \theta)}}{\tan(\frac{\pi}{2} - \phi - \theta)} $$
One of the biggest reasons I think I'm wrong is because the angle $\phi$ isn't defined with respect to the $x$- or $y$-axis. Letting me know if I'm on the right track or which one of my assumptions is incorrect would be of great help.
We have $Y + D = \dfrac { R }{\tan (\theta ‘ - \phi)}$ and $D = \dfrac {R}{\tan \theta ‘}$.
Y can be found by subtracting the two, provided R and the angles are known.
Assuming that X is the line marked as high-lighted.
Then, X = $R \tan \phi$. X and Y can then be related by eliminating R.