Calculate angle on bent bar based on height I'm writing a small piece of software that shows a preview of a bent rebar. I am however unable to figure out how to calculate the angle so the shape fits within given height $(B)$ requirements.
$A, B, C, D$ and R are known. I'm trying to calculate the angle V. Any ideas?

 A: Note: I'm going to use lowercase letters for the parameters and uppercase letters to identify certain points in the picture below.

From to the picture, we find


*

*$\overline{OQ} = r+d$

*$\overline{OM} = r+d$


and then the height of the green segment is
$$
\overline{MN} = \overline{OM}\cos\theta + \overline{OQ} =
(r+d)\,(\cos\theta+1)
$$
from which we get the height of the red segment:
$$
\overline{MS} = b - \overline{MN} = b - (r+d)\,(\cos\theta+1)
$$
On the other hand, the length of the blue segment is:
$$
\overline{ST} = [\,a - (r+d)\,]\cos\theta
$$
However, we also have
$$
\tan\theta = \frac{\overline{MS}}{\overline{ST}}
$$
so
$$
[\,a - (r+d)\,]\,\sin\theta = b - (r+d)\,(\cos\theta+1)
\qquad (1)
$$
Now define

$$
\alpha \equiv \frac{a}{r+d} - 1
\qquad\mbox{and}\qquad
\beta \equiv \frac{b}{r+d} - 1
$$

Since $0 \le b \le a$ and $a > (r+d)$ (see the pictures to understand why), we must have

$$
\alpha > 0 \qquad\mbox{and}\qquad
-1 \le \beta \le \alpha
$$

Then (1) reduces to

$$\alpha\sin\theta = \beta - \cos\theta \qquad (2)$$

Note that this equation correctly describes some "edge cases":
$\theta = 0 \iff \beta = 1 \iff b = 2(r+d)$

$\theta = \pi/2 \iff \beta = \alpha \iff b = a$

$\theta = \pi \iff \beta = -1 \iff b = 0$

Also, we expect that $\pi/2 < \theta < \pi$, hence $\cos\theta < 0$, for $\beta = 0$. I didn't draw that picture but it isn't difficult to see why that must be true. Indeed, from (2), setting $\beta = 0$, we find $\tan\theta = -1/\alpha$, implying $\cos\theta < 0$ (for $\theta$ in the second quadrant).
However, (2) does not uniquely determine $\theta$ for all possible values of $\alpha$ and $\beta$. To see why, consider the situation below. Both positions of the bar have the same values of $a$ and $b$ (hence, same $\alpha$ and $\beta$) but different values of $\theta$.

Now, back to (2). Squaring both sides, we find
$$\alpha\sin\theta = \beta - \cos\theta$$
$$\alpha^2\sin^2\theta = \beta^2 - 2\beta\cos\theta + \cos^2\theta$$
$$\alpha^2\,(1-\cos^2\theta) = \beta^2 - 2\beta\cos\theta + \cos^2\theta$$
$$(1+\alpha^2)\cos^2\theta - 2\beta\cos\theta + (\beta^2 - \alpha^2) = 0$$
whose solution is

$$
\cos\theta =
 \frac{\beta \pm \sqrt{\beta^2 - (1+\alpha^2)(\beta^2-\alpha^2)}}{(1+\alpha^2)}
$$

As expected, there are two solutions for each pair $(\alpha,\beta)$.
