计算 tikz 中的角度(光的分数),包括 sin^-1

计算 tikz 中的角度(光的分数),包括 sin^-1

我想在 tikzpicture 中用斯涅利乌斯定律计算偏转角 \beta。

我的代码是

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{amsmath} 
\usepackage{array} 
\usepackage{amssymb}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathmorphing} 
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\usepackage{mathtools}
\newcommand{\midarrow}{\tikz \draw[-triangle 60] (0,0) -- +(.1,0);} %voor pijltjes
\begin{document}
\begin{tikzpicture}[scale=1,cap=round,>=latex]
\tkzInit[ymin=-5,ymax=5,xmin=-5,xmax=5]
\tkzClip
%\tkzGrid
\tkzDefPoints{0/0/O, 10/1/D, 12/0.8/F};
\draw (O) circle(4cm);

\tkzDefShiftPoint[O](145:5){A}; 
\tkzDefShiftPoint[O](-120/3*2:5){B}; 
%\tkzDefShiftPoint[O]((3*5):5){C}; %% brackets don't work 

%circle
\foreach \x in {0,10,...,360} {\draw (\x:3.5cm) -- (\x:4cm);}
\foreach \x in {5,15,...,355} {\draw (\x:3.7cm) -- (\x:4cm);}
\foreach \x in {1,2,...,359} {\draw (\x:3.9cm) -- (\x:4cm);}
\draw[fill=gray!30] (O)-- +(0:3cm) arc (0:-180:3cm) -- cycle;
%%% tekenen van de invalshoek
\draw (A)-- node[sloped] {\midarrow} (O) ;
\draw (O)-- node[sloped] {\midarrow} (B) ;

%%% tekenen van de assen
\draw[black] (-4.5cm,0cm) -- (4.5cm,0cm) ;
\draw[black] (0cm,-4.5cm) -- (0cm,4.5cm) ;
\end{tikzpicture}
\end{document}

导致: 在此处输入图片描述

我发现在点的定义中可以计算一些东西。参见点 B。

但我的问题是:

1)使用括号会导致错误。

2)如何计算该角度定义中的 sin(a) 或 sin^-1(value)。

如果我有解决方案,我想创建一个宏,当阿尔法被赋予偏差指数时,该宏会自动计算偏差角(并绘制光束)。使用公式:n=sin(alfa)/sin(beta)

答案1

您可以使用sin(x)获取值 和asin(x)获取arcsin值。以下工作:

\pgfmathsetmacro{\nindex}{1.3}      %% n
\pgfmathsetmacro{\incident}{30}     %% angle of incidence
\pgfmathsetmacro{\inci}{90+\incident}
\pgfmathsetmacro{\refracted}{270+asin(sin(\incident)/\nindex)}

这样您就可以使用\inci\refracted来表示事件和refracted角度。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{array}
\usepackage{amssymb}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{tkz-euclide}
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\usepackage{mathtools}
\newcommand{\midarrow}{\tikz \draw[-triangle 60] (0,0) -- +(.1,0);} %voor pijltjes
\begin{document}
\pgfmathsetmacro{\nindex}{1.3}
\pgfmathsetmacro{\incident}{30}
\pgfmathsetmacro{\inci}{90+\incident}
\pgfmathsetmacro{\refracted}{270+asin(sin(\incident)/\nindex)}
    \begin{tikzpicture}[scale=1,cap=round,>=latex]
\tkzInit[ymin=-5,ymax=5,xmin=-5,xmax=5]
\tkzClip
%\tkzGrid
\tkzDefPoints{0/0/O, 10/1/D, 12/0.8/F};
\draw (O) circle(4cm);

%circle
\foreach \x in {0,10,...,360} {\draw (\x:3.5cm) -- (\x:4cm);}
\foreach \x in {5,15,...,355} {\draw (\x:3.7cm) -- (\x:4cm);}
\foreach \x in {1,2,...,359} {\draw (\x:3.9cm) -- (\x:4cm);}
\draw[fill=gray!30] (O)-- +(0:3cm) arc (0:-180:3cm) -- cycle;
%%% tekenen van de assen
\draw[black] (-4.5cm,0cm) -- (4.5cm,0cm) ;
\draw[black] (0cm,-4.5cm) -- (0cm,4.5cm) ;


\newcommand\lichtstraalbk[2]{%
\pgfmathsetmacro{\nindex}{#1}      %% n
\pgfmathsetmacro{\incident}{#2}     %% angle of incidence
\pgfmathsetmacro{\inci}{90+\incident}
\pgfmathsetmacro{\refracted}{270+asin(sin(\incident)/\nindex)}

\tkzDefShiftPoint[O](\inci:5){A}; 
\tkzDefShiftPoint[O](\refracted:5){B}; %%% 
\draw (A)-- node[sloped] {\midarrow} (O) ; %drawing the incidence
\draw (O)-- node[sloped] {\midarrow} (B) ; 
}

\lichtstraalbk{1.5}{30}


\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这只是 PSTricks 的另一种解决方案。

\documentclass[pstricks,margin=5mm]{standalone}
\usepackage{pstricks-add}

\def\Diagram#1{%
\begin{pspicture}[dimen=m,arrowscale=3](-6,-6)(6,6)
    \psframe*[linecolor=cyan!50](-6,0)(6,-6)
    \pscircle{5}
    \psline(-6,0)(6,0)
    \psline(0,-6)(0,6)
    \foreach \a in {0,10,...,350}{\psline(4.4;\a)(5;\a)}
    \foreach \a in {5,15,...,355}{\psline(4.6;\a)(5;\a)}
    \foreach \a in {1,2,...,359}{\psline(4.8;\a)(5;\a)}% kill unwanted whitespaces
    \pstVerb{/Angle #1 def /Index .75 def}
    \psset{ArrowInside=->}
    \psline(!6 Angle 90 add PtoC)(0,0)
    \psline(!6 Angle sin Index mul asin 270 add PtoC)
\end{pspicture}}


\begin{document}
\foreach \Angle in {10,20,...,80}{\Diagram{\Angle}}
\end{document}

在此处输入图片描述

相关内容