A triangle $KLM$ is given in the plane together with a point $A$ lying on the half-line opposite to $KL$. Construct a rectangle $ABCD$ whose vertices $B, C$ and $D$ lie on the lines $KM, KL$ and $LM$, respectively. (We allow the rectangle to be a square.)
1. **Coordinate System Setup**:
   - Place the coordinate origin at point \( A \) and align the positive x-axis along the ray \( AK \).
   - Let \( K = (k, 0) \) and \( \kappa = \tan \measuredangle MKL \). The equation of the line \( MK \) is \( y = \kappa(x - k) \).

2. **Point \( B \) on Line \( MK \)**:
   - Let \( B \) be an arbitrary point on \( MK \), so \( B = (x_B, y_B) \) where \( y_B = \kappa(x_B - k) \).

3. **Circle Center and Radius**:
   - The perpendicular bisector of segment \( [AB] \) intersects \( AK \) at the center \( O \) of the circle with radius \( [OA] = [OB] \).
   - The line \( BO \) intersects the circle again at point \( D = (x_D, y_D) \), where \( y_D = -y_B = -\kappa(x_B - k) \).

4. **Power of Point \( B_0 \)**:
   - Let \( B_0 \) be the perpendicular projection of \( B \) on \( AK \). The power of \( B_0 \) to the circle is given by:
     \[
     -x_B \cdot x_D = y_B \cdot y_D = -y_D^2
     \]

5. **Equation of Locus \( \mathcal{D} \)**:
   - Eliminate the arbitrary parameter \( x_B \) to find the equation of the locus \( \mathcal{D} \) of \( D \):
     \[
     \frac{y_D^2}{x_D} = x_B = -\frac{y_D}{\kappa} + k \implies h(x, y) = y^2 + \frac{xy}{\kappa} - kx = 0
     \]
   - This is the general equation of a conic section \( ax^2 + bxy + cy^2 + dx + ey + f = 0 \) with \( a = e = f = 0 \). Since \( b^2 - 4ac = \frac{1}{\kappa^2} > 0 \), it is a hyperbola.

6. **Asymptotes of the Hyperbola**:
   - The slopes of the asymptotes \( u \) and \( v \) are obtained by factoring the first three terms:
     \[
     ax^2 + bxy + cy^2 = y^2 + \frac{xy}{\kappa} = y \left(y + \frac{x}{\kappa}\right) = 0
     \]
   - The slopes are \( 0 \) and \( -\frac{1}{\kappa} \). Thus, one asymptote \( u \parallel AK \) and the other \( v \perp MK \).

7. **Equations of Asymptotes**:
   - Let the equations of the asymptotes be \( y = p \) and \( y = -\frac{x}{\kappa} + q \). For any \( (x, y) \in u \cup v \):
     \[
     0 = (y - p) \left(y + \frac{x}{\kappa} - q\right) = h(x, y) - \left(\frac{p}{\kappa} - k\right)x - (p + q)y + pq
     \]
   - Since \( h(x, y) = \text{const} \), we have \( h(x, y) = -pq \) and \( p = \kappa k \), \( q = -p = -\kappa k \).

8. **Intersection Points and Tangents**:
   - Let \( MK \) cut the y-axis at \( Q \) and let \( P \) be the reflection of \( Q \) in \( A \). The asymptote \( u \parallel AK \) passes through \( P \) and \( v \perp MK \) passes through \( Q \).
   - Since the absolute term of the hyperbola equation is \( 0 \), \( A \in \mathcal{D} \). Since \( A \) is the midpoint of \( [PQ] \), \( PQ \) is tangent to \( \mathcal{D} \) at \( A \).

9. **Hyperbola Center and Major Axis**:
   - The intersection \( X \equiv u \cap v \) is the hyperbola center. The internal bisector \( w \) of \( \measuredangle PXQ \) is the hyperbola major axis line.
   - Let \( E \) and \( F \) be the hyperbola foci, which need to be constructed.

10. **Construction of Foci**:
    - The hyperbola tangent \( PAQ \), bisecting \( \measuredangle FAE \), intersects the perpendicular bisector of \( [EF] \) through \( X \) at \( S \).
    - The circumcircle \( (Y) \) of \( \triangle AEF \), centered on \( XS \) and passing through \( A \) and \( S \), intersects the hyperbola major axis line \( w \) at the hyperbola foci \( E \) and \( F \).

11. **Hyperbola Vertices**:
    - The perpendicular projection \( E_0 \) of the focus \( E \) on the hyperbola tangent \( PQ \) lies on the hyperbola pedal circle \( (X) \), which intersects the hyperbola major axis line \( w \) at the hyperbola vertices \( U \) and \( V \).

12. **Circle Construction**:
    - Let \( (E) \) be a circle centered at \( E \) with radius \( [UV] \). Let \( F' \) be the reflection of \( F \) in \( LM \).
    - The two circles \( (D_1) \) and \( (D_2) \) through \( F \) and \( F' \), and externally tangent to \( (E) \) at \( T_1 \) and \( T_2 \), are centered on the line \( LM \).

13. **Intersection Points**:
    - Since \( [D_1E] - [D_1F] = [D_1E] - [D_1T_1] = [T_1E] = [UV] \) and similarly, \( [D_2E] - [D_2F] = [UV] \), \( D_1 \) and \( D_2 \in \mathcal{D} \) are intersections of the line \( LM \) and the hyperbola \( \mathcal{D} \).

14. **Radical Axes and Tangents**:
    - Let \( (G) \) be an arbitrary circle through \( F \) and \( F' \), preferably intersecting \( (E) \) at \( J \) and \( J' \). The radical axes \( FF' \) and \( JJ' \) of circle pairs \( (D_1), (G) \) and \( (E), (G) \) meet at the radical center \( R \) of \( (D_1), (E), (G) \).
    - Tangents \( RT_1 \) and \( RT_2 \) of \( (E) \) from \( R \) are radical axes of externally tangent circle pairs \( (D_1), (E) \) and \( (D_2), (E) \). Thus, \( D_1 \equiv ET_1 \cap LM \) and \( D_2 \equiv ET_2 \cap LM \).

15. **Circumcenters of Rectangles**:
    - The perpendicular bisectors of \( [AD_1] \) and \( [AD_2] \) intersect the line \( AK \) at the circumcenters \( O_1 \) and \( O_2 \) of rectangles \( AB_1C_1D_1 \) and \( AB_2C_2D_2 \), respectively, providing the two problem solutions.

The final answer is the construction of the rectangles \( \boxed{ AB_1C_1D_1 } \) and \( AB_2C_2D_2 \).