几何光学

几何光学

可以用更简单的方式、更少的代码来制作这个光线追踪图。

\documentclass{article}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[ymin=-3,ymax=5.5,xmin=-7,xmax=7]
\tkzClip
%\tkzGrid
\tkzDefPoints{5/0/C', -5/0/C, -1.25/0/O, -2.5/0/F,  0/0/S}
\tkzDefShiftPoint[O](90:1.5){VV};
\tkzDefShiftPoint[O](-90:1.5){W};
\tkzDefCircle[radius](C,S)
\tkzGetLength{rCSpt}
\tkzpttocm(\rCSpt){rCScm}
\tkzDrawArc[angles, color=black](C,S)(320,40)
\tkzDrawPoints(C, O,S,F)
\tkzLabelPoints(C, O, S,F)
\tkzDrawLines[add= 0.2 and 0.1](C,S S,C');
\fill[pattern=north east lines]
(S) arc[start angle=180,end angle=220,radius=-\rCScm cm] --
++(10pt,0pt) arc[start angle=220,end angle=140,radius=-\rCScm cm] --
++(-10pt,0pt) arc[start angle=140,end angle=180,radius=-\rCScm cm];
\tkzDefPointBy[translation= from O to S](VV)
\tkzGetPoint{D}
\tkzDefPointBy[translation= from O to S](W)
\tkzGetPoint{W'}
\tkzInterLC(VV,D)(C,S) \tkzGetPoints{G}{E}
\tkzDrawLines[-latex, thick,color=red, add= 0 and 2](E,F)
\tkzInterLL(O,VV)(E,F)
\tkzGetPoint{I}
\tkzInterLC(VV,C)(C,S) \tkzGetPoints{H}{J}
\tkzDrawSegments[-latex, thick,color=red](VV,H)
\tkzInterLL(VV,C)(D,F)
\tkzGetPoint{N}
\tkzInterLL(H,N)(E,F)
\tkzGetPoint{M}
\tkzDefShiftPoint[M](90:3){P}
\tkzInterLL(C,S)(M,P)
\tkzGetPoint{Q}
\tkzDrawSegments[-latex, thick,color=red](VV,E VV,J)
\tkzDrawSegments[-latex, very thick](Q,M O,VV)
\tkzDrawLines[-latex, dashed,color=red, add= 0 and 0.5](E,M H,N)
\end{tikzpicture}
\end{document}

在此处输入图片描述

本规范基于 Gonzalo Medina 在这个答案

答案1

嗯,我不知道这是否更简单,或者代码是否更少。这更像是另一种方法,使用 TiZ(实际上,与您发布的那个没什么不同)。正如 Alain Matthes 在评论中所说,最好的解决方案可能是tikz-opctics因为它是为这种绘图设计的,但我自己从未使用过它。

对于 TiZ 解决方案我们希望使用calc库来定位一些点,最重要的是intersections库。这样我们就可以像手工绘制一样绘制图片。

例如:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{calc,intersections}
\tikzset{ray/.style={red,-latex},object/.style={thick,blue,-latex}}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
% dimensions
\def\r {4}  % mirror radius
\def\a{30}  % mirror angle
\def\ox{3}  % object position
\def\oy{1}  % object height
% known coordinates
\coordinate (C)  at (0,0);
\coordinate (F)  at (0.5*\r,0);
\coordinate (O)  at (\ox,0);
\coordinate (S)  at (\r,0);
\coordinate (C1) at (\ox,\oy);
% intersections
\draw[thick,name path=horizontal] (C) + (-1,0) --++ (7,0);
\path[name path=C ray]            (C) -- ($(C1)!-3cm!(C)$);
\path[name path=horizontal ray]   (C1) --++ (4,0);
\path[name path=mirror]           (\a:\r) arc (\a:-\a:\r);
\path[name intersections={of=C ray and mirror,by={C2}}];
\path[name intersections={of=horizontal ray and mirror,by={F1}}];
\path[name path=F ray]            (F) -- ($(F1)!-2cm!(F)$);
\path[name intersections={of=C ray and F ray,by={C3}}];
\path[name path=image]            (C3) --++ (0,-3);
\path[name intersections={of=image and horizontal,by={I}}];
% rays
\draw[ray,densely dashed] (C2) -- ($(C3)!-1cm!(C)$);
\draw[ray,densely dashed] (F1) -- ($(C3)!-1cm!(F1)$);
\draw[ray,shorten <=-1cm] (C)  -- (C2);
\draw[ray,shorten >=-3cm] (C1) -- (F1) -- (F);
% mirror, object, image
\fill[gray,opacity=0.2]   (C)  +  (\a:\r) arc (\a:-\a:\r) --++ (0.25,0) arc (-\a:\a:\r) -- cycle;
\draw                     (C)  +  (\a:\r) arc (\a:-\a:\r);
\draw[object]             (O)  -- (C1);
\draw[object,dashed]      (I)  -- (C3);
% labels
\foreach\i in {C,O,F,I}
  \fill (\i) circle (1pt) node [below]      {$\i$};
  \fill (S)  circle (1pt) node [below left] {$S$};
% uncomment the following to see the coordinates
%\foreach\i in {C1,C2,C3,F1} \node[circle,cyan,fill=white,inner sep=0] at (\i) {\tiny$\i$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容