Beja.
Here you are the project.
The formula I obtain is based only in two trigonometry formulas:
h^2 = a^2 + b^2 = r^2 + b^2
b = h * sin(ang)
x = h - r
If you solve this, you can obtain x.
Note: When you "Run" the project with the B4a Program, in the "Logs" zone, you can see the results (in the PC, not in the mobile device).
I use this in "Release mode" and I can see all the results loged. You don't need to debug it.
Regards.