TikZ 实物图/圆锥体绘制

TikZ 实物图/圆锥体绘制

我目前正在尝试在 TikZ 中绘制以下图片:

图片

然而,我很难画出两个朝特定方向的圆锥体。

感谢@Schrödinger 的猫。我根据他的锥体解决方案完成了这幅图(附有德语文本):

\documentclass[tikz,border=3mm]{standalone}
\newcounter{iloop}
\usetikzlibrary{arrows}
\usepackage{tikz-3dplot}
\tikzset{pics/ycone/.style={code={
\tikzset{cone/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/cone/##1}}
\path (0,0,0) coordinate (-tip);
\begin{scope}[canvas is xz plane at y=\pv{h}/1cm]
 \path[/tikz/cone/base] (0,0) coordinate(-base) circle[radius=\pv{r}];
 \setcounter{iloop}{0}%
 \pgfmathsetmacro{\myangleA}{0}%
 \pgfmathsetmacro{\myangleB}{0}%
 \pgfmathsetmacro{\myvisangleA}{-180}%
 \pgfmathsetmacro{\myvisangleB}{180}%
 \loop%
 \path (\number\value{iloop}:\pv{r}) coordinate (taux);
 \pgfmathanglebetweenlines%
   {\pgfpointanchor{-tip}{center}}{\pgfpointanchor{-base}{center}}
   {\pgfpointanchor{-tip}{center}}{\pgfpointanchor{taux}{center}}%  
 \edef\testangle{\pgfmathresult}%
 \pgfmathsetmacro\testangle{sin(\testangle)}
 \ifdim\testangle pt<\myangleA pt\relax%
  \pgfmathsetmacro{\myangleA}{\testangle}%
  \pgfmathsetmacro{\myvisangleA}{\value{iloop}}%
 \fi
 \ifdim\testangle pt>\myangleB pt\relax%
  \pgfmathsetmacro{\myangleB}{\testangle}%
  \pgfmathsetmacro{\myvisangleB}{\value{iloop}}%
 \fi
 \stepcounter{iloop}\ifnum\value{iloop}<361\repeat
 \ifdim\myvisangleB pt>180 pt
  \pgfmathsetmacro{\myvisangleB}{\myvisangleB-360}
 \fi
  \path[/tikz/cone/mantle] (\myvisangleA:\pv{r})
   arc(\myvisangleA:\myvisangleB:\pv{r})
   -- (-tip) -- cycle;
\end{scope}
}},cone/.cd,base/.style={draw,fill=green!60!gray,fill opacity=0.4},
mantle/.style={draw,fill=green!30!black,fill opacity=0.4},
r/.initial=1cm,h/.initial=2cm}
\begin{document}
\tdplotsetmaincoords{60}{165}
\begin{tikzpicture}[tdplot_main_coords,line cap=round]
 \draw[ultra thick, red] (.3,-2,.5) -- (0,0,0);

 \fill[blue!20,opacity=.8] (-1,0,-1) -- (1,0,-1) -- (1,0,.5) -- (-1,0,.5) -- cycle;
 \fill[blue!30,opacity=.8] (-1,-0.5,.5) -- (1,-0.5,.5) -- (1,0,.5) -- (-1,0,.5) -- cycle;
 \fill[blue!50,opacity=.8] (1,-0.5,.5) -- (1,0,.5) -- (1,0,-1) -- (1,-0.5,-1) -- cycle;

  \draw[ultra thick, red,shorten >=1mm] (0,0,0) -- (.5,9.5,0);
 \tdplotsetrotatedcoords{3}{00}{0}
 \path[tdplot_rotated_coords] 
    pic{ycone={r=1.5cm,h=6cm}};
 \tdplotsetrotatedcoords{-5}{00}{0}
 \path[tdplot_rotated_coords] 
    pic{ycone={r=1.5cm,h=9cm}};
  \draw[ultra thick, red,-*] (.33,6.5,0) -- (.5,9.5,0);

  \draw[thick, green] (0,0,0) -- (1.8,9.5,0);
  \draw[thick, green,-stealth'] (1.8,9.5,0) -- (2.1,9.5,0);
  \draw[thick, green,-stealth'] (1.8,9.5,0) -- (1.5,9.5,0);
  \draw[thick, green,-stealth'] (1.8,9.5,0) -- (1.8,9.5,-.3);
  \draw[thick, green,-stealth'] (1.8,9.5,0) -- (1.8,9.5,.3);

  \draw[thick, green] (0,0,0) -- (-1.05,9.5,0);
  \draw[thick, green,-stealth'] (-1.05,9.5,0) -- (-1.35,9.5,0);
  \draw[thick, green,-stealth'] (-1.05,9.5,0) -- (-.75,9.5,0);
  \draw[thick, green,-stealth'] (-1.05,9.5,0) -- (-1.05,9.5,.3);
  \draw[thick, green,-stealth'] (-1.05,9.5,0) -- (-1.05,9.5,-.3);

 \draw[dashdotted, gray!50!black] (0,0,0) -- (.38,7.5,1);
 \draw[dashdotted, gray!50!black] (0,0,0) -- (.38,7.5,0);
 \draw[dashdotted, gray!50!black] (0,0,0) -- (.38,7.5,-1);

  % Annotation
  \path[-stealth',black,shorten >=1mm] (-.3,-1.5,1) edge node[anchor=west,pos=0] {Laserstrahl} (.3,-1.5,.5);

  \path[-stealth',black,shorten >=1mm] (-2,0,.5)  edge node[anchor=west,pos=0] {Kristall} (-1,0,0) ;

  \path[-stealth',black,shorten >=1mm] (-2,2.3,.5)  edge node[anchor=west,pos=0,text width=2cm,align=center] {Vertikal polarisierte Photonen} (-1,2.3,0) ;

  \path[-stealth',black,shorten >=1mm] (2,3,-.5)  edge node[anchor=east,pos=0,text width=2cm,align=center] {Horizontal polarisierte Photonen} (1,4,-.5) ;

  \path[-stealth',black,shorten >=1mm] (.5,10.5,-1)  edge node[anchor=north,pos=0,text width=2cm,align=center] {verschränkte Photonen} (-1.05,9.5,0)
        edge (1.8,9.5,0) ;

 \end{tikzpicture}
\end{document}

最终版本的图片

答案1

这画出了这样的锥体。

\documentclass[tikz,border=3mm]{standalone}
\newcounter{iloop}
\usepackage{tikz-3dplot}
\tikzset{pics/ycone/.style={code={
\tikzset{cone/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/cone/##1}}
\path (0,0,0) coordinate (-tip);
\begin{scope}[canvas is xz plane at y=\pv{h}/1cm]
 \path[/tikz/cone/base] (0,0) coordinate(-base) circle[radius=\pv{r}];
 \setcounter{iloop}{0}%
 \pgfmathsetmacro{\myangleA}{0}%
 \pgfmathsetmacro{\myangleB}{0}%
 \pgfmathsetmacro{\myvisangleA}{-180}%
 \pgfmathsetmacro{\myvisangleB}{180}%
 \loop%
 \path (\number\value{iloop}:\pv{r}) coordinate (taux);
 \pgfmathanglebetweenlines%
   {\pgfpointanchor{-tip}{center}}{\pgfpointanchor{-base}{center}}
   {\pgfpointanchor{-tip}{center}}{\pgfpointanchor{taux}{center}}%  
 \edef\testangle{\pgfmathresult}%
 \pgfmathsetmacro\testangle{sin(\testangle)}
 \ifdim\testangle pt<\myangleA pt\relax%
  \pgfmathsetmacro{\myangleA}{\testangle}%
  \pgfmathsetmacro{\myvisangleA}{\value{iloop}}%
 \fi
 \ifdim\testangle pt>\myangleB pt\relax%
  \pgfmathsetmacro{\myangleB}{\testangle}%
  \pgfmathsetmacro{\myvisangleB}{\value{iloop}}%
 \fi
 \stepcounter{iloop}\ifnum\value{iloop}<361\repeat
 \ifdim\myvisangleB pt>180 pt
  \pgfmathsetmacro{\myvisangleB}{\myvisangleB-360}
 \fi
  \path[/tikz/cone/mantle] (\myvisangleA:\pv{r})
   arc(\myvisangleA:\myvisangleB:\pv{r})
   -- (-tip) -- cycle;
\end{scope}
}},cone/.cd,base/.style={draw,fill=green!60!black,fill opacity=0.4},
mantle/.style={draw,fill=green!30!gray,fill opacity=0.4},
r/.initial=1cm,h/.initial=2cm}
\begin{document}
\tdplotsetmaincoords{60}{165}
\begin{tikzpicture}[tdplot_main_coords,line cap=round]
 \fill[blue!20] (-1,0,-1) -- (1,0,-1) -- (1,0,1) -- (-1,0,1) -- cycle;
 \fill[blue!30] (-1,-0.5,1) -- (1,-0.5,1) -- (1,0,1) -- (-1,0,1) -- cycle;
 \fill[blue!50] (1,-0.5,1) -- (1,0,1) -- (1,0,-1) -- (1,-0.5,-1) -- cycle;
 \tdplotsetrotatedcoords{3}{00}{0}
 \path[tdplot_rotated_coords] 
    pic{ycone={r=1.5cm,h=6cm}};
 \tdplotsetrotatedcoords{-5}{00}{0}
 \path[tdplot_rotated_coords] 
    pic{ycone={r=1.5cm,h=9cm}};
 \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容