How to automatically draw the images of a point placed between 2 inclined mirrors?

\documentclass[pstricks,border=20pt,12pt]{standalone}
\usepackage{pst-eucl,pst-plot}
\def\Angle{37}
\def\R{5}

\begin{document}
\begin{pspicture}[showgrid](-\R,-\R)(\R,\R)
    \pstGeonode[PointSymbol=none,PosAngle={45,-90},PointNameSep=24pt](\R;\Angle){B}(0,0){O}(\R;0){A}
    \pcline[linecolor=lightgray,linewidth=12pt,offset=-6pt,strokeopacity=0.6](O)(A)
    \pcline[linecolor=lightgray,linewidth=12pt,offset=6pt,strokeopacity=0.6](O)(B)
    \psline(B)(O)(A)
    \pstMarkAngle[MarkAngleRadius=1.6,LabelSep=.8]{A}{O}{B}{$\theta$}
    \pstGeonode(!3 \Angle\space 2 div PtoC){X}
    \pstOrtSym{O}{A}{X}[I_1] \psline[linestyle=dotted](X)(I_1)
    \newif\ifA \Afalse
    \pstFPDiv\No{360}{\Angle}
    \multido{\iA=1+1,\iB=2+1}{\numexpr\No-1}{%
      \ifA\pstOrtSym{O}{A}{I_\iA}[I_\iB]\else\pstOrtSym{O}{B}{I_\iA}[I_\iB]\fi
      \psline[linestyle=dotted](I_\iA)(I_\iB)
      \ifA\Afalse\else\Atrue\fi
    }%
    \pscircle[linestyle=dotted](O){3}
\end{pspicture}

\end{document}

enter image description here

and with both directions:

\documentclass[pstricks,border=20pt,12pt]{standalone}
\usepackage{pst-eucl,pst-plot}
\def\Angle{37}
\def\R{5}

\begin{document}
\begin{pspicture}[showgrid](-\R,-\R)(\R,\R)
    \pstGeonode[PointSymbol=none,PosAngle={45,-90},PointNameSep=24pt](\R;\Angle){B}(0,0){O}(\R;0){A}
    \pcline[linecolor=lightgray,linewidth=12pt,offset=-6pt,strokeopacity=0.6](O)(A)
    \pcline[linecolor=lightgray,linewidth=12pt,offset=6pt,strokeopacity=0.6](O)(B)
    \psline(B)(O)(A)
    \pstMarkAngle[MarkAngleRadius=1.6,LabelSep=.8]{A}{O}{B}{$\theta$}
    \pstGeonode(!3 \Angle\space 2 div PtoC){X}
    \color{blue}\psset{linecolor=blue}%
    \pstOrtSym{O}{A}{X}[I_1] \psline[linestyle=dotted](X)(I_1)
    \newif\ifA \Afalse
    \pstFPDiv\No{360}{\Angle}
    \multido{\iA=1+1,\iB=2+1}{\numexpr\No-1}{%
      \ifA\pstOrtSym{O}{A}{I_\iA}[I_\iB]\else\pstOrtSym{O}{B}{I_\iA}[I_\iB]\fi
      \psline[linestyle=dotted](I_\iA)(I_\iB)
      \ifA\Afalse\else\Atrue\fi
    }%
    \color{red}\psset{linecolor=red}%
    \pstOrtSym{O}{B}{X}[I_1] \psline[linestyle=dotted](X)(I_1)
    \newif\ifA \Atrue
    \pstFPDiv\No{360}{\Angle}
    \multido{\iA=1+1,\iB=2+1}{\numexpr\No-1}{%
      \ifA\pstOrtSym{O}{A}{I_\iA}[I_\iB]\else\pstOrtSym{O}{B}{I_\iA}[I_\iB]\fi
      \psline[linestyle=dotted](I_\iA)(I_\iB)
      \ifA\Afalse\else\Atrue\fi
    }%
    \pscircle[linestyle=dotted](O){3}
\end{pspicture}

\end{document}

enter image description here


Another attempt with MetaPost, strongly modified. if k-1=floor(360/theta), it checks if the "k"th image is equal to the original point X, and in that case prints "Success!" besides this point. Else it prints "failed!". Possibility to make any number of attempts one likes, it suffices to modify the "theta" parameter. Thus it is easy to check that if 360/theta is an integer, the number of images is indeed 360/theta - 1. But I'm still not sure if it is what was wanted…

input latexmp; 
setupLaTeXMP(options = "12pt",  
    mode = rerun, 
    textextlabel = enable, 
    multicolor=enable,
    packages="SIunits");

u:=1.5cm; % for scaling
% Angle
numeric theta; theta = 30; 
% Supposed number of images
hypothesis := 360/theta-1;
number_of_images := floor(hypothesis);
% mirrors
numeric eps; eps = 0.4*u; % mirrors thickness
pair A, B, X; 
path mirror[]; 
A := (5u, 0); 
mirror1 = origin -- A -- A-(0, eps) -- (0, -eps) -- cycle; 
mirror2 = mirror1 reflectedabout(origin, A) rotated theta;
B:= point 1 of mirror2; 

beginfig(0);
% Grid and labels
drawoptions(dashed withdots);
for i = -5 upto 5:
    draw (-5, i)*u -- (5, i)*u;
    draw (i, -5)*u -- (i, 5)*u;
    label.bot("$" & decimal(i) & "$", (i*u, -5*u));
    label.lft("$" & decimal(i) & "$", (-5u, i*u));
endfor;
% mirrors drawing
drawoptions();
draw mirror1 ; fill mirror1 withcolor 0.8white ; draw origin -- A;
draw mirror2 ; fill mirror2 withcolor 0.8white; draw origin--B;
label.rt("$A$", A); label.rt("$B$", B);
% The angle drawing and its label
draw anglebetween(origin--A, origin--B, "$\theta =" & decimal(theta) & "\degree$");
% X
pair X[]; X0 = (3, 1)*u; freedotlabel("$X$", X0, origin);
draw X0 withpen pencircle scaled 3bp;
% Placement of floor(360/theta-1) images of X 
drawoptions(dashed evenly);
k:=1; 
forever:
    exitunless k <= number_of_images;
    X[k] = X[k-1] reflectedabout(origin,
        if (k = round(k/2)*2): A else: B fi);
    draw X[k-1]--X[k];
    draw X[k] withpen pencircle scaled 3bp;
    freedotlabel("$X_{" & decimal(k) & "}$", X[k], origin);
    k := k+1;
endfor;
% Success or no success?
X[k]= X[k-1] reflectedabout(origin, if (k = round(k/2)*2): A else: B fi);
if (abs(X[k]-X0)< 1e-12):
    draw X[k-1] -- X0;
    freedotlabel("$X$\ \textcolor{red}{Success!}", X0, origin)
else:
    draw X[k-1] -- X[k];
    freedotlabel("$X$", X0, origin);
    freedotlabel("\textcolor{red}{Failed!}", X[k], origin)
fi; 
% The circle
draw fullcircle scaled (2*abs(X1)) dashed withdots;
endfig;
end.

enter image description here

enter image description here