![改变此 3D tikz 图像中的螺旋方向](https://linux22.com/image/473471/%E6%94%B9%E5%8F%98%E6%AD%A4%203D%20tikz%20%E5%9B%BE%E5%83%8F%E4%B8%AD%E7%9A%84%E8%9E%BA%E6%97%8B%E6%96%B9%E5%90%91.png)
我正在尝试在 Tikz 中使用不同的视角创建“3d”图像(参见平均能量损失下面)。我创建的图像可以在此链接。
我的问题是,我创建的螺旋线与黑轴不对齐。具体来说,蓝色螺旋线的旋转轴应该围绕黑线(不一定沿着黑轴的整个长度)。
螺旋代表圆偏振光,这里@MarkWibrow。我怎样才能对齐螺旋线,使其围绕黑线所示的轴旋转?解决方案似乎在这个帖子,但我无法将其合并到这里。
另外,我怎样才能减小螺旋的振幅(即更小的圆圈)?
平均能量损失
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{3d, shapes.multipart, angles, quotes}
\tikzset{axis/.style={black, very thick, ->}}
\newcommand{\rect}[1]{%
\begin{scope}[canvas is xz plane at y=1.2]
\draw[line join=round, thick, fill=green!50!black!40] (#1,-1.2) rectangle (#1+1.2,1.2);
\end{scope}
%
\begin{scope}[canvas is xy plane at z=1.2]
\draw[line join=round, thick, fill=green!50!black!25](#1,-1.2) rectangle (#1+1.2,1.2);
\end{scope}
%
\begin{scope}[canvas is yz plane at x=#1]
\draw[line join=round, thick, fill=green!50!black!10] (-1.2,-1.2) rectangle (1.2,1.2);
\end{scope}
}
\begin{document}
\pgfdeclarelayer{layer1}
\pgfdeclarelayer{layer2}
\pgfdeclarelayer{layer3}
\pgfdeclarelayer{layer4}
\pgfdeclarelayer{layer5}
\pgfdeclarelayer{layer6}
\pgfdeclarelayer{layer7}
\pgfdeclarelayer{layer8}
\pgfsetlayers{main, layer8, layer7, layer6, layer5, layer4, layer3, layer2, layer1}
\begin{tikzpicture}[x={(1cm,0.4cm)}, y={(8mm, -3mm)}, z={(0cm,1cm)}, line cap=round, line join=round]
\draw[axis] (-1,0,0) -- (15,0,0);
\begin{pgfonlayer}{layer8}
\rect{14}
\end{pgfonlayer}
\begin{pgfonlayer}{layer8}
\draw[very thick] (13,0,0) -- (14,0,0);
\end{pgfonlayer}
\tikzset{%
xyz path/.style args={\x=#1; \y=#2; \z=#3; (#4)}{
insert path={
\foreach \step [evaluate={\x=#1; \y=#2; \z=#3;}] in {#4}{
-- (\x, \y, \z) }
}
},
cosine path/.style args={#1:#2}{
xyz path={\x=cos(\step); \y=0; \z=\step/360; (#1, 2, ..., #2)},
insert path={ coordinate (cosine path end) }
},
sine path/.style args={#1:#2}{
xyz path={\x=0; \y=sin(\step); \z=\step/360; (#1, 2, ..., #2)},
insert path={ coordinate (sine path end) }
},
spiral path/.style args={#1:#2}{
xyz path={\x=cos(\step); \y=sin(\step); \z=\step/360; (#1, 2, ..., #2)},
insert path={ coordinate (spiral path end) }
},
marker/.style={
insert path={
node [fill, circle, inner sep=0pt, minimum size=#1] {}
}
}
}
\def\lastangle{15}
\def\cycles{4}
\foreach \cycle in {0,...,\cycles}{
\tikzset{shift={(0, 0, \cycle)}}
\ifnum\cycle=\cycles
\let\endangle=\lastangle
\else
\def\endangle{360}
\fi
\draw [transform shape, blue, very thick] (1, 0, 0) [spiral path={0:\endangle}];
}
\end{tikzpicture}
\end{document}
答案1
我已将您的坐标系改为右手坐标系。
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[x={(-1cm,-0.4cm)}, y={(0.8cm, -0.3cm)}, z={(0cm,1cm)}, line join=round]
\draw[canvas is xz plane at y=1.2, thick, fill=green!50!black!40] (-14,-1.2) rectangle (-15.2,1.2);
\draw[canvas is xy plane at z=1.2, thick, fill=green!50!black!25] (-14,-1.2) rectangle (-15.2,1.2);
\draw[canvas is yz plane at x=-14, thick, fill=green!50!black!10] (-1.2,-1.2) rectangle (1.2,1.2);
\draw[very thick, ->] (-14,0,0) -- (0,0,0);
\draw[blue, very thick] plot[domain=-12:-1, samples=200, smooth, variable=\t] (\t,{0.5*cos(8*\t r)},{0.5*sin(8*\t r)});
\end{tikzpicture}
\end{document}
螺旋从 到-12
,-1
半径为0.5
,8
控制圈数。