3

I'm trying to animate total reflection.. so I need to evaluate the second angle inside the \foreach loop, I tried \pgfmathparse{asin(1.33*sin(deg(\th))}, but I got the error !missing number, treated as zero

\documentclass[border=10pt,tikz]{standalone}
\usepackage{xcolor}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
\usepackage{tikz}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{decorations.markings}
\tikzstyle arrowstyle=[scale=1]
\tikzstyle directed=[postaction={decorate,decoration={markings,
    mark=at position .65 with {\arrow[arrowstyle]{stealth}}}}]
\tikzstyle reverse directed=[postaction={decorate,decoration={markings,
    mark=at position .65 with {\arrowreversed[arrowstyle]{stealth};}}}]
    
    \begin{document}
    
        \foreach \th in {180,185,190,...,265}
    {\begin{tikzpicture}[scale=0.75]
    % define coordinates
    \coordinate (O) at (0,0) ;
    \coordinate (A) at (0,4) ;
    \coordinate (B) at (0,-4) ;
    \def\n1{1.33}
    \def\n2{1}
    \def\r{4cm}

    
    % media
    \fill[blue!10!,opacity=.3] (-4,0) rectangle (4,4);
    \fill[myblue,opacity=.3] (-4,0) rectangle (4,-4);
    \node[right] at (2,2) {Fast $n_2$};
    \node[left] at (-2,-2) {Slow $n_1$};

    % axis
    \draw[dash pattern=on5pt off3pt] (A) -- (B) ;

    % rays
    \draw[red,ultra thick,directed] (\th:\r) -- (O);
    \pgfmathparse{asin(1.33*sin(deg(\th))}
    \draw[blue,directed,ultra thick,,reverse directed] (O) -- (\pgfmathresult:\r);


\end{tikzpicture}}

    \end{document}

I'm trying to add angles to the code provided below and also to remove the grey ray when \pgfmathresult<49, but I'm getting the error Missing number for the first one, and for the second one, shouldn't the command line \fi \draw[gray,directed,ultra thick] (O) -- ({-(90-\th)}:\r); means that the line will not be drawn unless \pgfmathresult>49?

\begin{document}

\foreach \th in {0,4,...,48,48.8,54,...,90} {%
\begin{tikzpicture}[scale=0.75,ang/.style = {draw, Straight Barb-Straight Barb, anchor=center}] % define coordinates

        \def\n1{1.33}
        \def\n2{1}
        \def\r{4cm}
        \coordinate (O) at (0,0) ;
        \coordinate (A) at (0,4) ;
        \coordinate (B) at (0,-4) ;
        \coordinate (C) at ({90-asin(1.33*sin(\th)) }:\r);
       \coordinate (D) at  ({270-\th}:\r);
       \coordinate (E) at  (90:\r);
       \coordinate (F) at  (270:\r);


        % media
        \fill[blue!10!,opacity=.3] (-4,0) rectangle (4,4);
        \fill[myblue,opacity=.3] (-4,0) rectangle (4,-4);
        \node[right] at (2,2) {Fast $n_2$};
        \node[left] at (-2,-2) {Slow $n_1$};

        % axis
        \draw[dash pattern=on5pt off3pt] (A) -- (B) ;

        % rays


        \draw[lava,ultra thick,directed] ({270-\th}:\r) -- (O);
        \pgfmathparse{int(\th)}
        \ifnum\pgfmathresult<49
            \draw[myblue,directed,ultra thick] (O) -- ({90-asin(1.33*sin(\th)) }:\r);
        \fi
        \draw[gray,directed,ultra thick] (O) -- ({-(90-\th)}:\r);
            \pic [draw,Straight Barb-Straight Barb, anchor=center, angle radius = 4mm, angle eccentricity=1.5, "$ \theta_i$"] {angle = F--O--D};
\pic [draw,Straight Barb-Straight Barb, anchor=center,angle radius = 4mm, angle eccentricity=1.5,  "$ \theta$"] {angle = E--O--C};
    \end{tikzpicture}
}

\end{document}

1
6

The error occurs because acrsine does not exist for angles greater than 90. After limiting refraction, total internal reflection occurs. Therefore, it is no longer possible to calculate the angle of the refracted ray as you try.

\documentclass[border=10pt,tikz]{standalone}
\usepackage{xcolor}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{decorations.markings}
\tikzstyle arrowstyle=[scale=1]
\tikzstyle directed=[postaction={decorate,decoration={markings,
    mark=at position .65 with {\arrow[arrowstyle]{stealth}}}}]
\tikzstyle reverse directed=[postaction={decorate,decoration={markings,
    mark=at position .65 with {\arrowreversed[arrowstyle]{stealth};}}}]

    
\begin{document}

\foreach \th in {0,4,...,48,48.8,54,...,90} {%    
        \begin{tikzpicture}[scale=0.75]
            % define coordinates
            \coordinate (O) at (0,0) ;
            \coordinate (A) at (0,4) ;
            \coordinate (B) at (0,-4) ;
            \def\n1{1.33}
            \def\n2{1}
            \def\r{4cm}


            % media
            \fill[blue!10!,opacity=.3] (-4,0) rectangle (4,4);
            \fill[myblue,opacity=.3] (-4,0) rectangle (4,-4);
            \node[right] at (2,2) {Fast $n_2$};
            \node[left] at (-2,-2) {Slow $n_1$};

            % axis
            \draw[dash pattern=on5pt off3pt] (A) -- (B) ;

            % rays


            \draw[red,ultra thick,directed] ({270-\th}:\r) -- (O);
            \pgfmathparse{int(\th)}
            \ifnum\pgfmathresult<49
                \draw[blue,directed,ultra thick] (O) -- ({90-asin(1.33*sin(\th)) }:\r);
            \fi
            \draw[gray,directed,ultra thick] (O) -- ({-(90-\th)}:\r);
        \end{tikzpicture}
    }

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.