4

I want to add a parameter to a tikz command. I now have 5 ray's on a mirror, but I want to make it possible to add an angle and a point on the mirror where to ray reflects on the mirror. So is it possible to change the location of point B with a parameter in the command \lichtraalwk and I want to change the angle of the ray (which is now in the A). So that I don't have 5 times the same figure.

\documentclass{article}
\usepackage{tkz-euclide}
\usepackage{tikz}
\usetkzobj{all} 
\newcommand{\midarrow}{\tikz \draw[-triangle 60] (0,0) -- +(.1,0);}

\begin{document}
\begin{tikzpicture}
\tkzInit[ymin=0,ymax=5,xmin=0,xmax=10]
\tkzClip
%\tkzGrid
\tkzDefPoints{0/1/C, 10/1/D, 12/0.8/F}

\newcommand\lichtstraalwk{
\tkzDefPoints{5/1/B}
\tkzDefShiftPoint[B](135:4){A};
\tkzDefShiftPoint[B](90:2){K};
\tkzDefShiftPoint[B](-90:3){L};
\tkzDefPointBy[reflection = over K--L](A) \tkzGetPoint{E};
\draw (A)-- node[sloped,pos=0.2] {\midarrow} (B) ;
\draw[orange] (B)-- node[sloped,pos=0.6] {\midarrow} (E);
\tkzDrawSegment[very thick](C,D);
\draw[dashed] (K) -- (L) ;
}

\begin{scope}[xshift=-2cm,yshift=0cm] \lichtstraalwk \end{scope}
\begin{scope}[xshift=-1cm,yshift=0cm] \lichtstraalwk \end{scope}
\begin{scope}[xshift=0cm,yshift=0cm]  \lichtstraalwk \end{scope}
\begin{scope}[xshift=1cm,yshift=0cm]  \lichtstraalwk \end{scope}
\begin{scope}[xshift=2cm,yshift=0cm]  \lichtstraalwk \end{scope}
\draw [fill,pattern=north east lines,draw=none] (C) rectangle (F);

\end{tikzpicture}

\end{document}

enter image description here

So that I can make something like this: enter image description here

1 Answers1

3

Like this?

\documentclass{article}
\usepackage{tkz-euclide}
 %\usepackage{tikz}
\usetkzobj{all}
\newcommand{\midarrow}{\tikz \draw[-triangle 60] (0,0) -- +(.1,0);}

\begin{document}
\begin{tikzpicture}
\tkzInit[ymin=0,ymax=5,xmin=0,xmax=10]
\tkzClip
%\tkzGrid

\newcommand\lichtstraalwk[2]{%
\tkzDefPoints{0/1/C, 10/1/D, 12/0.8/F}   %% moved inside \newcommand
\tkzDefPoints{#1/1/B}
\tkzDefShiftPoint[B](#2:4){A};
\tkzDefShiftPoint[B](90:2){K};
\tkzDefShiftPoint[B](-90:3){L};
\tkzDefPointBy[reflection = over K--L](A) \tkzGetPoint{E};
\draw (A)-- node[sloped,pos=0.2] {\midarrow} (B) ;
\draw[orange] (B)-- node[sloped,pos=0.6] {\midarrow} (E);
\tkzDrawSegment[very thick](C,D);
\draw[dashed] (K) -- (L) ;
\draw [fill,pattern=north east lines,draw=none] (C) rectangle (F);   %% this too moved inside
}

\foreach \x/\ang in {4/135,5/165}{
\lichtstraalwk{\x}{\ang}
}

\end{tikzpicture}

\end{document}

enter image description here

Here is the bonus:

\documentclass{article}
\usepackage{tkz-euclide}
%\usepackage{tikz}
\usetkzobj{all}
\newcommand{\midarrow}{\tikz \draw[-triangle 60] (0,0) -- +(.1,0);}

\begin{document}
\begin{tikzpicture}
\tkzInit[ymin=0,ymax=5,xmin=0,xmax=10]
\tkzClip
%\tkzGrid
\newcommand\lichtstraalwk[2]{%
\tkzDefPoints{0/1/C, 10/1/D, 12/0.8/F}   %% this moved inside
\tkzDefPoints{#1/1/B}
\tkzDefPoint(85:4){A}
%\tkzDefShiftPoint[B](135:4){A};
\tkzDefShiftPoint[B](90:6){K};
\tkzDefShiftPoint[B](-90:3){L};
\tkzDefPointBy[reflection = over K--L](A) \tkzGetPoint{E};
\draw (A)-- node[sloped,pos=0.2] {\midarrow} (B) ;
\draw[orange] (B)-- node[sloped,pos=0.6] {\midarrow} (E);
\tkzDrawSegment[very thick](C,D);
\draw[dashed] (K) -- (L) ;
\draw [fill,pattern=north east lines,draw=none] (C) rectangle (F);   %% this too moved inside
}

\foreach \x in {2,5}{
\lichtstraalwk{\x}
}

\end{tikzpicture}

\end{document}

enter image description here