我有代码
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,bending}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{3d}
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane
}
\makeatother
\NewDocumentCommand{\DrawCoordinateGrid}{O{} m m m m m m}{%
\def\XGridMin{#2}
\def\XGridMax{#3}
\def\YGridMin{#4}
\def\YGridMax{#5}
\def\ZGridMin{#6}
\def\ZGridMax{#7}
%
\begin{scope}[canvas is xy plane at z=0, thin, red]
\draw [#1] (\XGridMin,\YGridMin) grid (\XGridMax,\YGridMax);
\end{scope}
\begin{scope}[canvas is yz plane at x=0, thin, blue]
\draw [#1] (\YGridMin,\ZGridMin) grid (\YGridMax,\ZGridMax);
\end{scope}
\begin{scope}[canvas is xz plane at y=0, thin, orange]
\draw [#1] (\XGridMin,\ZGridMin) grid (\XGridMax,\ZGridMax);
\end{scope}
}%
\NewDocumentCommand{\DrawCoordinateAxis}{O{} m m m m m m}{%
\def\XAxisMin{#2}
\def\XAxisMax{#3}
\def\YAxisMin{#4}
\def\YAxisMax{#5}
\def\ZAxisMin{#6}
\def\ZAxisMax{#7}
%
\begin{scope}[thin, gray, -latex]
\draw [#1] (\XAxisMin,0,0) -- (\XAxisMax,0,0) node [below left] {$x$};
\draw [#1] (0,\YAxisMin,0) -- (0,\YAxisMax,0) node [right] {$y$};
\draw [#1] (0,0,\ZAxisMin) -- (0,0,\ZAxisMax) node [above] {$z$};
\end{scope}
}%
% A macro to save repeating the code
\newcommand*{\DrawTriangle}{%
\begin{scope}[canvas is xy plane at z=0]
\draw [fill=yellow!50,opacity=0.6] (0,1) -- (3,0) -- (0,4) -- cycle;
\end{scope}
}%
\begin{document}
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,
declare function={pX=2;}]
\begin{scope}[canvas is yz plane at x=0]
\draw (-pX,-pX) coordinate (bl1) -- (pX,-pX) coordinate (br1)
-- (pX,pX) coordinate (tr1) -- (-pX,pX) coordinate (tl1) -- cycle;
\draw[stealth-stealth] (0,pX) node[below left]{$$}
-- (0,0) -- (pX,0) node[below left]{$$};
\pgflowlevelsynccm
\draw[-{Latex[bend]}] (2,0) arc(0:380:1);
\draw[-{Latex[bend]}] (0,-1) arc(-90:290:1);
\draw[-{Latex[bend]}] (0,0) arc(-90:380:1);
\end{scope}
%\foreach \X in {bl,tl,br,tr}
%{\draw[-latex] (\X1) -- ++ (1,0,0);}
%
%\draw (0,0,0) -- (4,0,0);
% plane
\fill[gray,fill opacity=0] (-1,-4,0) -- (7,-4,0) --
(7,4,0) -- (-1,4,0) -- cycle;
\begin{scope}[canvas is yz plane at x=4]
\draw (-pX,-pX) coordinate (bl2) -- (pX,-pX) coordinate (br2)
-- (pX,pX) coordinate (tr2) -- (-pX,pX) coordinate (tl2) -- cycle;
\draw[stealth-stealth];
\end{scope}
%\draw[-latex] (4,0,0) -- (5.5,0,0) node[below left]{$$};
\begin{scope}[canvas is xy plane at z=0]
\begin{scope}
\clip (0,-2) rectangle (4,3);
\draw[densely dashed] (0,-2) -- (0,2);
\foreach \X in {0.25,0.75,...,5}
{\pgfmathsetmacro{\myrnd}{rnd*360}
\foreach \Y in {-1.75,-1.25,...,1.75}
{
%\draw[-stealth] ({\X-0.2*cos(\myrnd)},{\Y-0.2*sin(\myrnd)}) --
%({\X+0.2*cos(\myrnd)},{\Y+0.2*sin(\myrnd)});
}
\draw[densely dashed] (\X+.25,-2) -- (\X+0.25,2);}
\end{scope}
%Put here for y rotation!
\end{scope}
%
\begin{scope}[shift={($(-4,0,0)-(0,0,0)$)}]
\begin{scope}[canvas is xy plane at z=0,dashed]
\foreach \X in {2.1,2.3,...,4}
{\begin{scope}
\pgflowlevelsynccm
%\draw[-latex,thin] (1*\X,0) -- (1*\X,{-2*sin(\X*180)});
\end{scope}
}
% \draw plot[smooth,domain=2:4,samples=41] (1*\x,{-2*sin(\x*180)});
\begin{scope}
\pgflowlevelsynccm
% \draw[-latex,ultra thin,solid] (12.2,0) -- (12.8,0);
\end{scope}
\end{scope}
\begin{scope}[canvas is xz plane at y=0]
\foreach \X in {2.1,2.3,...,4}
{\begin{scope}
\pgflowlevelsynccm
% \draw[-latex,thin] (1*\X,0) -- (1*\X,{2*sin(\X*180)});
\end{scope}
}
%\draw plot[smooth,domain=2:4,samples=41] (1*\x,{2*sin(\x*180)});
\end{scope}
\node at (1*3.5,1.75,0) {$$};
\node at (1*3.5,0,-1.25) {$$};
\end{scope}
%
\pgfmathsetseed{42}
\begin{scope}[shift={($(4,0,0)-(0,0,0)$)},
declare function={amp(\x)=3*exp(-\x)*(0.6+0.8*rnd)*sin(\x*180);}]
\path (0,0,0) coordinate (B0) coordinate (E0);
\begin{scope}[canvas is xy plane at z=0,dashed]
\foreach \X [count=\Y] in {0.2,0.4,...,3}
{\begin{scope}
\pgfmathsetmacro\myamp{-amp(\X)}
\path (1*\X,\myamp) coordinate(B\Y);
\pgfmathtruncatemacro{\itest}{ifthenelse(abs(\myamp)>0.075,1,0)}
\ifnum\itest=1
\pgflowlevelsynccm
%\draw[-latex,thin] (1*\X,0) -- (1*\X,\myamp);
\fi
\xdef\Ymax{\Y}
\end{scope}
}
%\draw plot[smooth,samples at={0,...,\Ymax}] (B\x);
\begin{scope}
\path (4.8,0);
\pgflowlevelsynccm
\draw[-latex,ultra thin,solid] (4.2,0) -- (4.8,0);
\end{scope}
\end{scope}
\begin{scope}[canvas is xz plane at y=0]
\foreach \X [count=\Y] in {0.2,0.4,...,3}
{\begin{scope}
\pgfmathsetmacro\myamp{amp(\X)}
\path (1*\X,\myamp) coordinate(E\Y);
\pgfmathtruncatemacro{\itest}{ifthenelse(abs(\myamp)>0.075,1,0)}
\ifnum\itest=1
\pgflowlevelsynccm
%\draw[-latex,thin] (1*\X,0) -- (1*\X,\myamp);
\fi
\xdef\Ymax{\Y}
\end{scope}
}
% \draw plot[smooth,samples at={0,...,\Ymax}] (E\x);
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}
输出以下图像我一直试图改变它,但没有成功。我想让平面上的每条虚线都包含圆,就像我在原点处画的那样,半径各不相同。有人能帮我修改一下代码吗?
答案1
这添加了那些圆圈。您的代码有很多不必要的部分。如果您添加代码片段的来源链接就更好了。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,bending}
% \makeatletter % only necessary for very old installations
% \tikzoption{canvas is xy plane at z}[]{%
% \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
% \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
% \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
% \tikz@canvas@is@plane
% }
% \makeatother
\begin{document}
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,
declare function={pX=2;},
pics/circles/.style={code={
\pgflowlevelsynccm
\draw[-{Latex[bend]}] (2,0) arc(0:380:1);
\draw[-{Latex[bend]}] (0,-1) arc(-90:290:1);
\draw[-{Latex[bend]}] (0,0) arc(-90:380:1);
}}]
\begin{scope}[canvas is yz plane at x=0]
\draw (-pX,-pX) coordinate (bl1) -- (pX,-pX) coordinate (br1)
-- (pX,pX) coordinate (tr1) -- (-pX,pX) coordinate (tl1) -- cycle;
\draw[stealth-stealth] (0,pX) -- (0,0) -- (pX,0);
\pic[transform shape]{circles};
\draw[densely dashed,very thin] (-pX,0) -- (pX,0);
\end{scope}
\draw[densely dashed] foreach \X in {1,...,7}
{ (\X/2,-pX,0) -- coordinate (p\X) (\X/2,pX,0)};
\begin{scope}[canvas is yz plane at x=4]
\draw (-pX,-pX) coordinate (bl2) -- (pX,-pX) coordinate (br2)
-- (pX,pX) coordinate (tr2) -- (-pX,pX) coordinate (tl2) -- cycle;
\path foreach \X in {1,...,7}
{(p\X) pic[transform shape]{circles}};
\pic[transform shape]{circles};
\draw[densely dashed,very thin] (-pX,0) -- (pX,0);
\end{scope}
\end{tikzpicture}
\end{document}
对于不同的半径,你可以使用
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,bending}
% \makeatletter % only necessary for very old installations
% \tikzoption{canvas is xy plane at z}[]{%
% \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
% \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
% \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
% \tikz@canvas@is@plane
% }
% \makeatother
\begin{document}
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,
declare function={pX=2;},
pics/circles/.style={code={
\pgflowlevelsynccm
\draw[-{Latex[bend]}] (2,0) arc(0:380:#1);
\draw[-{Latex[bend]}] (0,-1) arc(-90:290:#1);
\draw[-{Latex[bend]}] (0,0) arc(-90:380:#1);
}},pics/circles/.default=1]
\begin{scope}[canvas is yz plane at x=0]
\draw (-pX,-pX) coordinate (bl1) -- (pX,-pX) coordinate (br1)
-- (pX,pX) coordinate (tr1) -- (-pX,pX) coordinate (tl1) -- cycle;
\draw[stealth-stealth] (0,pX) -- (0,0) -- (pX,0);
\pic[transform shape]{circles};
\draw[densely dashed,very thin] (-pX,0) -- (pX,0);
\end{scope}
\draw[densely dashed] foreach \X in {1,...,7}
{ (\X/2,-pX,0) -- coordinate (p\X) (\X/2,pX,0)};
\begin{scope}[canvas is yz plane at x=4]
\draw (-pX,-pX) coordinate (bl2) -- (pX,-pX) coordinate (br2)
-- (pX,pX) coordinate (tr2) -- (-pX,pX) coordinate (tl2) -- cycle;
\foreach \X in {1,...,7}
{\pgfmathsetmacro{\myradius}{1-1/(10-\X)}
\path(p\X) pic[transform shape]{circles=\myradius};}
\pic[transform shape]{circles={0.5}};
\draw[densely dashed,very thin] (-pX,0) -- (pX,0);
\end{scope}
\end{tikzpicture}
\end{document}
变化被编码在 中\pgfmathsetmacro{\myradius}{1-1/(10-\X)}
。我不知道你在想什么。