File:InterferenceGrating.gif
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
InterferenceGrating.gif (683 × 446 pixels, file size: 827 KB, MIME type: image/gif, looped, 31 frames, 16 s)
File information
Structured data
Captions
Summary[edit]
DescriptionInterferenceGrating.gif |
English: Spectroscopy with an optical grating
Deutsch: Optisches Gitter: Beugungsordnungen und Spektroskopie |
Date | |
Source | Own work |
Author | And1mu |
Similar graphics[edit]
Source Code[edit]
created with LaTeX and PGF/TikZ |
---|
Script to create the animation: #!/bin/bash
set -eu
DIR="animate"
FILE="Spektrum"
NUM=0
rm -f ${DIR}/frame???.png
for ANG in $(seq 400 10 700) ; do
# POS=$(echo "30*c($ANG/45*a(1))" | bc -l)
echo $ANG
sed -i "s/\\\def\\\wavelength{.\+}/\\\def\\\wavelength{$ANG}/" $FILE.tex
# echo "Creating frame $NUM for $ANG ..."
pdflatex -shell-escape $FILE.tex 1> /dev/null
echo "Convert to png ..."
NUMSTR=$(printf "%03d" $NUM)
convert -density 100 ${FILE}01.svg -shave 3 ${DIR}/frame${NUMSTR}.png
NUM=$(($NUM+1))
done
cd $DIR
#convert -delay 40 -loop 1000 frame*.png ${FILE}.gif
convert -set delay '%[fx:(t<n-1)?20:1000]' -loop 100 frame*.png ${FILE}.gif
cd -
The code to create a single frame: \documentclass[crop,border=5,tikz,convert={outext=,
command=\unexpanded{pdf2svg \infile\space\outfile\%02d.svg
all}},multi=false]{standalone}
\usetikzlibrary{math,calc,through,shapes,patterns,decorations.pathmorphing}
\usepackage{ifthen}
\usepackage{bm}
\def\static{1} % 1: for static graphic
\def\lpmm{625}
\def\wavelength{700}
\newcommand{\markangle}[6][0.25]{
\begin{scope}
\clip (#2)--(#3)--(#4);
\node (ANG) [draw, circle, minimum size=#5] at (#3){};
\end{scope}
\coordinate (E1) at (intersection 0 of ANG and #3--#2);
\coordinate (E2) at (intersection 0 of ANG and #3--#4);
%\draw[thick] (E1) to [bend right=50] (E2);
\coordinate (EM) at ($ (E1)!0.5!(E2) $);
\coordinate (EM) at ($ (EM)!#1!(#3) $);
\node[fill=white, inner sep=2] at (EM) {#6};
}
\newcommand{\rainbow}[1]{
%% #1 = 0: circle, #1 = 1: rectangle
\foreach \n in {1,...,10}{
\foreach \swl in {400,403,...,\wavelength}{
\pgfmathsetmacro{\myarg}{ \n*\swl/1000.*\lpmm/1000 }
\pgfmathsetmacro{\myarg}{ \myarg < 0.98 ? \myarg : 0}
\ifthenelse{\lengthtest{ \myarg pt = 0 pt}}{}{
\LAMBDAtoRGB{\swl}
\tikzmath{ \myalpha = asin(\myarg);}
\tikzmath{ \mx = 7*tan(\myalpha);}
\tikzmath{ \mn = \n*\n;}
\ifthenelse{ #1 = 0 }{
\coordinate (A+) at (90-\myalpha:6+0.075*\mn);
\coordinate (B+) at (90-\myalpha:8-0.075*\mn);
\coordinate (A-) at (90+\myalpha:6+0.075*\mn);
\coordinate (B-) at (90+\myalpha:8-0.075*\mn);
\pgfmathsetmacro{\mywidth}%
{0.14*\n*\lpmm/100/sqrt(1-\myarg*\myarg)}
}{
\coordinate (A+) at (-\mx,6.05+0.05*\mn);
\coordinate (B+) at (-\mx,7.95-0.05*\mn);
\coordinate (A-) at (\mx,6.05+0.05*\mn);
\coordinate (B-) at (\mx,7.95-0.05*\mn);
\pgfmathsetmacro{\mywidth}{\myarg < 0.92 ?%
0.4*\n*3/10*\lpmm/100/(1-\myarg*\myarg)^(3/2)%
: 0}
}
\draw[beamcolor,line width=\mywidth] (A+)--(B+);
\draw[beamcolor,line width=\mywidth] (A-)--(B-);
\ifthenelse{ \static = 1 }{
\ifthenelse{ \swl = 502 }{
\ifthenelse{ #1 = 0 }{
\node[] at (90+\myalpha:8.3){$+\n$};
\node[] at (90-\myalpha:8.3){$-\n$};
}{
\pgfmathsetmacro{\mxm}{\mx > 12 ? 11 : \mx}
\node[] at (-\mxm,8.3){$+\n$};
\node[] at (\mxm,8.3){$-\n$};
}
}{}
}{}
}{}
}
}
}
\newcommand{\drawbeam}[2]{
\pgfmathsetmacro{\myarg}{ \n*#1/1000.*\lpmm/1000 }
\pgfmathsetmacro{\myarg}{ \myarg < 0.98 ? \myarg : 0 }
\ifthenelse{\lengthtest{\myarg pt = 0 pt}}{}{
\tikzmath{ \myalpha = asin(\myarg); }
\LAMBDAtoRGB{#1}
\ifthenelse{ #2 = 0 }{
\coordinate (A+) at (90+\myalpha:8);
\coordinate (A-) at (90-\myalpha:8);
}{
\tikzmath{ \mx = 7*tan(\myalpha); }
\coordinate (A+) at (-\mx,7);
\coordinate (A-) at (\mx,7);
\draw[beamcolor,thick] (\mx,6)--(\mx,8);
\draw[beamcolor,thick] (-\mx,6)--(-\mx,8);
}
\draw[beamcolor,thick] (A+) -- (0,0) -- (A-);
\ifthenelse{ \static = 0 }{
\node[beamcolor,fill=white] at (90+\myalpha:5) {$+\n$};
\node[beamcolor,fill=white] at (90-\myalpha:5) {$-\n$};
\node[anchor=west,beamcolor] at (0.7,-1.2){
\Large $\bm{\lambda=#1\;\mathrm{nm}}$};
\ifthenelse{\n < 3}{
\markangle[0.1]{A+}{0,0}{0,6}{220-50*\n}{$\alpha_\n$}
\pgfmathprintnumberto[precision=2]{\myalpha}{\roundedalpha}
\node[anchor=west,beamcolor] at (4,-0.3-0.6*\n){
$\bm{\alpha_\n=\roundedalpha^\circ}$};
}{}
}{
\ifthenelse{ \n = 1 \AND #1 = 430 }{
\markangle[0.1]{A+}{0,0}{0,6}{220-50*\n}{$\alpha_\n$}
}{}
}
}
}
\newcommand{\info}[2]{
\LAMBDAtoRGB{#1}
\node[anchor=west,beamcolor,fill=white] at (0.7,-0.3-#2*0.5){
\Large $\bm{\lambda=#1\;\mathrm{nm}}$};
\draw[beamcolor,fill=beamcolor]
(-0.4,-0.1-0.5*#2)rectangle(0.4,-0.6-0.5*#2);
}
\newcommand{\laser}{
\LAMBDAtoRGB{\wavelength}
\draw[white,line width=1.4mm] (0,6.2)--(0,7.8);
\draw[beamcolor,thick] (0,0) -- (0,8);
\ifthenelse{ \static = 0 }{
\fill[beamcolor] (-0.4,-2)rectangle(0.4,-0.6);
\node[beamcolor,fill=white] at (0,5){$0$};
}{
\node[] at (0,8.3){$0$};
}
\draw[beamcolor,ultra thick] (0,-0.6) -- (0,0);
\draw[black,ultra thick,opacity=0.6] (-1,0)--(1,0)
node[right]{\LARGE $g=\frac{1}{\lpmm}\;\mathrm{mm}$};
\node[anchor=east,draw,text width=3.5cm,text centered] at
(-1.5,-0.4){
\LARGE $\sin\alpha_n=\frac{n\cdot\lambda}{g}$\\
\normalsize $n=0,\pm 1,\pm 2,\dots$};
}
\begin{document}
\include{LaserColor}
\begin{tikzpicture}[>=latex,scale=1]
\clip(-8.4,-2.4)rectangle(8.4,8.5);
\begin{scope}
\clip (168.8:8)arc(168.8:11.2:8)--(11.2:6)arc(11.2:168.8:6)--cycle;
\fill[black] (0,0) circle (8);
\fill[white] (0,0) circle (6.0);
\end{scope}
\foreach \n in {1,...,10}{
\ifthenelse{ \static = 0 }{
\drawbeam{\wavelength}{0}
}{
\foreach \wl/\s in {430/1,532/2,633/3}{
\drawbeam{\wl}{0}
\info{\wl}{\s}
}
}
}
\rainbow{0}
\laser
\end{tikzpicture}
\begin{tikzpicture}[>=latex,scale=1]
\clip(-12.4,-2.4)rectangle(12.4,8.5);
\fill[black](-12.4,6)rectangle(12.4,8);
\rainbow{1}
\foreach \n in {1,...,10}{
\ifthenelse{ \static = 0 }{
\drawbeam{\wavelength}{1}
}{
\foreach \wl/\s in {430/1,532/2,633/3}{
\drawbeam{\wl}{1}
\info{\wl}{\s}
}
}
}
\laser
\end{tikzpicture}
\end{document}
The code to find RGB from wavelenght [1] (slightly modified) LaserColor.tex: \newcommand{\LAMBDAtoRGB}[1]{
\def\locallambda{#1}
\def\red{0.0}
\def\green{0.0}
\def\blue{0.0}
\def\t{0.0}
\tikzmath{
if ( \locallambda >= 400.0 && \locallambda < 410.0 ) then {
\t = (\locallambda-400.0)/(410.0-400.0);
\red = (0.345*\t)-(0.20*\t*\t);
} else {
if ( \locallambda >= 410.0 && \locallambda < 475.0) then {
\t = (\locallambda-410.0)/(475.0-410.0);
\red = 0.15-(0.15*\t*\t);
} else {
if ( \locallambda >= 545.0 && \locallambda < 595.0 ) then {
\t = (\locallambda-545.0)/(595.0-545.0);
\red = +(1.98*\t)-(\t*\t);
} else {
if ( \locallambda >= 595.0 && \locallambda < 650.0 ) then {
\t = (\locallambda-595.0)/(650.0-595.0);
\red = 0.98+(0.06*\t)-(0.40*\t*\t);
} else {
if ( \locallambda >= 650.0 && \locallambda < 700.0 ) then {
\t = (\locallambda-650.0)/(700.0-650.0);
\red = 0.64-(0.84*\t)+(0.20*\t*\t);
};
};
};
};
};
}
\tikzmath{
if ( \locallambda >= 415.0 && \locallambda < 475.0 ) then {
\t = (\locallambda-415.0)/(475.0-415.0);
\green = +(0.80*\t*\t);
} else {
if ( \locallambda >= 475.0 && \locallambda < 590.0 ) then {
\t = (\locallambda-475.0)/(590.0-475.0);
\green = 0.8 +(0.76*\t)-(0.80*\t*\t);
} else {
if ( \locallambda >= 590.0 && \locallambda < 639.0 ) then {
\t = (\locallambda-590.0)/(639.0-590.0);
\green = 0.76-(0.76*\t);
};
};
};
}
\tikzmath{
if ( \locallambda >= 400.0 && \locallambda < 475.0 ) then {
\t = (\locallambda-400.0)/(475.0-400.0);
\blue = +(2.20*\t)-(1.50*\t*\t);
} else {
if ( \locallambda >= 475.0 && \locallambda < 560.0 ) then {
\t = (\locallambda-475.0)/(560.0-475.0);
\blue = 0.7 -(\t)+(0.30*\t*\t);
};
};
}
\definecolor{beamcolor}{rgb}{\red,\green,\blue}
}
|
Licensing[edit]
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 15:29, 29 October 2017 | 683 × 446 (827 KB) | And1mu (talk | contribs) | many small improvements | |
16:01, 23 October 2017 | 652 × 439 (839 KB) | And1mu (talk | contribs) | minor cosmetic optimizations | ||
21:22, 21 October 2017 | 653 × 439 (841 KB) | And1mu (talk | contribs) | show angles | ||
13:19, 21 October 2017 | 652 × 437 (784 KB) | And1mu (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following 4 pages use this file: