Finding the rectangle surrounding a capsule defined by two points while minimizing trig, and square root For the visuals of a simulation I need to solve the following problem.

I know points one and two (shown in yellow) and the length of the green line. I need to find the four purple points surrounding the capsule this creates. This capsule is basically constructed as a rectangle between the two points with the width of a green line. Then a semicircle is added to each end with a radius matching the width of the rectangle (green line).
This would be an easy task just using polar coordinates however two issues come to mind.


*

*Each drawing has direction, somehow c1 and c2 need to be on the same side as p1, and c3 and c4 need to be on the same side as p2. Because sometimes p1 will be to the left or below p2 this poses problems.

*This calculation has to be preformed by an old cpu thousands of times many times a second. If at all possible a minimum amount of trigonometric and square root operations preformed.


So far I have been able to find the location of the 4 corners of the inner rectangle (black) by normalizing the vector between the two points, multiplying by the width. Then I use that value and add or subtract it from p1 in order to find those corners.
Theoretically this same method could be used if I could find the location of the point that bisects the line made by c1 and c2 (and c3 and c4). However I would have to use 2 cosines, and 2 sines in order to figure that out. And I would likely have issues with order of points.
Is there a faster way that also keeps p1, c1, and c2 on the same side?
 A: 
Let your position vector be $\vec{P_1}=[x_1,y_1]$ and your direction vector between $P_1$ and $P_2$ be normalized $\vec{u}= \dfrac{[x_2-x_1,y_2-y_1]}{d}$ where $d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$.
Let $\vec{n}=\dfrac{[y_2-y_1,x_1-x_2,]}{d}$ be a normal vector to segment $P_1P_2$. Then $\vec{c_3}$ and $\vec{c_4}$ are the two vectors $\vec{P_1}+(d+r)\vec{u}\pm r\vec{n}$ and the vectors $\vec{c_1}$ and $\vec{c_2}$ are $\vec{P_1}-r\vec{u}\pm r\vec{n}$.
Given the labeling of your diagram I believe the equations would be as follows:
\begin{equation}
\vec{c_1}=\vec{P_1}-r(\vec{u}-\vec{n})
\end{equation}
\begin{equation}
\vec{c_2}=\vec{P_1}-r(\vec{u}+\vec{n})
\end{equation}
\begin{equation}
\vec{c_3}=\vec{P_1}+(d+r)\vec{u}-r\vec{n}
\end{equation}
\begin{equation}
\vec{c_4}=\vec{P_1}+(d+r)\vec{u}+r\vec{n}
\end{equation}
A: Let $$p_i = (x_i, y_i), \quad i \in \{1, 2\}$$ and let $w$ be the capsule width.  The desired points of the bounding rectangle are given by $$\begin{align*} 
\left( x_1 + \frac{w}{2d} (x_1 - x_2 - y_1 + y_2), y_1 + \frac{w}{2d} (x_1 - x_2 + y_1 - y_2) \right), \\
\left( x_1 + \frac{w}{2d} (x_1 - x_2 + y_1 - y_2), y_1 + \frac{w}{2d} (-x_1 + x_2 + y_1 - y_2) \right), \\
\left( x_2 + \frac{w}{2d} (-x_1 + x_2 - y_1 + y_2), y_2 + \frac{w}{2d} (x_1 - x_2 - y_1 + y_2) \right), \\ 
\left( x_2 + \frac{w}{2d} (-x_1 + x_2 + y_1 - y_2), y_2 + \frac{w}{2d} (-x_1 + x_2 - y_1 + y_2) \right),
\end{align*}$$ where $d = |p_1 - p_2| = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}$ is the distance between $p_1$ and $p_2$.
A: Can your restrict the angles to specific values?  For example, is one degree accuracy on the angle good enough or can you force the angle to be a multiple of one degree?  Then you can make a table of sines at startup and use the fact that $\cos \theta^\circ = \sin (90-\theta)^\circ$.  Then you don't need any square roots, either, because you have both $\sin$ and $\cos$.  A table of $9,000$ entries can give you $0.01^\circ$ resolution.
