Move a rectangle along the tangent of a circle point We have to rotate a rectangle along the circle at an angle $\theta$ and then move the rectangle along the tangent for a distance 'lateral offset' as given in the following image

I calculated the lateral offset factors to be applied on the rectangle (after rotating it) coordinates as given below. Reference - How to find the third coordinate of a right triangle given 2 coordinates and lengths of each side
        Slope = tan(θ);
        SlopeLateralOffset = -1.0 / Slope;
        LateralOffsetTranslationFactor = LateralOffset / sqrt(1.0 + SlopeLateralOffset  * SlopeLateralOffset);

        LateralOffsetTranslationX = LateralOffsetTranslationFactor ;
        LateralOffsetTranslationY = SlopeLateralOffset  * LateralOffsetTranslationFactor ;

Is the logic that I applied correct? I think that the formula SlopeLateralOffset = -1.0 / Slope, will not work always as I cannot form a right triangle with radius r and lateral offset
What changes should I make it to work? Can you please help me?
 A: Let's start with defining the coordinate system. Say origin is at the bottom of the circle, at the intersection of brown and green lines in the left figure. You also measure $\theta$ from the vertical line downwards from the center of the circle. Then the position of the intersection of black and green lines in the middle figure are
$$\begin{align}x_r&=r\sin\theta\\y_r&=r(1-\cos\theta)\end{align}$$
Now draw the horizontal line through $(x_r, y_r)$. It should be easy for you to show that the angle between the horizontal and the green line is also $\theta$, measured from the horizontal. Then if you move LateralOffset along the line, the horizontal and vertical components of just this motion are
$$x_L=\mathrm{LateralOffset}\cdot\cos\theta\\y_L=\mathrm{LateralOffset}\cdot\sin\theta$$
So the final coordinate of the point on the rectangle is going to be $$x=x_r+x_L\\y=y_r+y_L$$and the rectangle is going to be tilted an angle $\theta$ from the original configuration.
A: Another approach is to consider how we can rotate point $(x_b, y_b)$ by angle $\theta$ (counterclockwise) around point $(x_c, y_c)$.  Let the rotated point be $(x_a, y_a)$:
$$\left [ \begin{matrix} x_a \\ y_a \end{matrix} \right ] = \left [ \begin{matrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{matrix} \right ] \left [ \begin{matrix} x_b - x_c \\ y_b - y_c \end{matrix} \right ] + \left [ \begin{matrix} x_c \\ y_c \end{matrix} \right ] \tag{1}\label{G1}$$
The center matrix is the counterclockwise rotation around origin by angle $\theta$ in 2D.  Because it rotates around origin, we move the center of rotation to origin, by subtracting the rotation center coordinates from the coordinates of the point we are rotating.  After the rotation, we need to add back the coordinates we subtracted, to move the origin back to where it was originally.
In the original diagram, the center of rotation is at distance $r$ exactly above the center of the rectangle.  If we choose the center of the rectangle before rotation and translation as the origin, then the center of rotation is
$$\left[ \begin{matrix} x_c \\ y_c \end{matrix} \right] = \left[ \begin{matrix} 0 \\ r \end{matrix} \right] \tag{2a}\label{G2a}$$
If we additionally choose $L$ as the lateral offset, we can move the rectangle right (positive $x$) before the rotation by that amount, and then do the rotation (noting that the center of rotation is not moved!), getting the correct position for the result.  Thus, the point we are trying to rotate is
$$\left[ \begin{matrix} x_b \\ y_b \end{matrix} \right] = \left[ \begin{matrix} L \\ 0 \\ \end{matrix} \right] \tag{2b}\label{G2b}$$
Substituting $\eqref{G2a}$ and $\eqref{G2b}$ to $\eqref{G1}$ yields
$$\left[ \begin{matrix} x_a \\ y_a \end{matrix} \right] = \left[ \begin{matrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{matrix} \right] \left[ \begin{matrix} L \\ - r \end{matrix} \right] + \left[ \begin{matrix} 0 \\ r \end{matrix} \right] \tag{2c}\label{G2c}$$
If you are unfamiliar with matrix notation, the above is equivalent to
$$\left\lbrace \begin{aligned}
x_a &= L \cos\theta + r \sin\theta \\
y_a &= L \sin\theta - r \cos\theta + r \\
\end{aligned} \right. \tag{2d}\label{G2d}$$
In summary, the center of the rectangle moves by $(x_a, y_a)$ relative to its original position:
$$\left\lbrace \begin{aligned}
x_a &= L \cos\theta + r \sin\theta \\
y_a &= L \sin\theta + r (1 - \cos\theta) \\
\end{aligned} \right. \tag{3}\label{G3}$$
where $x$ increases right, $y$ up, and $\theta$ counterclockwise.
