我一直试图画这个,但无法给它上色或创建网格。有人能帮帮我吗?
这是我的 MWE:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
% Arc
\draw(0.66,1.26) arc (37:90:0.8 and 1.8);% left arc
\draw(3.3,1.3) arc (37:90:-0.8 and 1.8);% left arc
% Lines
\draw (2,3) -- (0,2);% line 1
\draw (2,3) -- (4,2);% line 2
\draw (2,2) -- (0.66,1.3);% line 3
\draw (2,2) -- (3.3,1.3);% line 4
\draw (0,2) -- (0,1.4);% line 5
\draw (0,1.4) -- (0.66,1.3);% line 6
\draw (4,2) -- (4,1.5);% line 7
\draw (4,1.5) -- (3.3,1.3);% line 8
\draw (-1.25,1.5) node {$\phi$};
\end{tikzpicture}
\end{document}
答案1
为此,我建议你perspective
和3d
Ti钾Z 库。后者允许将坐标系更改为位于与轴平行的平面上的二维坐标系,选项如下(例如)
[canvas is xy plane at z=2]
在上面的例子中,我们将参考系更改为位于高度 z=2、与 xy 平面平行的平面上的新参考系。
也就是说,需要参数化两个圆柱体的相交曲线。它们在平面 y=x 处相交,因此一种可能性是
(sin(t), sin(t), cos(t)), t∈[0,90]
最后,实际上回答你的问题,可以用循环生成网格\foreach
。
一个完整的例子可能是:
% https://tex.stackexchange.com/questions/670532/draw-l-shaped-half-cylinder
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d,perspective}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,3d view={120}{30}]
% Axes
\draw[-latex] (0,0,0) -- (4,0,0) node[below] {$x$};
\draw[-latex] (0,0,0) -- (0,4,0) node[below] {$y$};
\draw[-latex] (0,0,0) -- (0,0,2) node[above] {$z$};
% Inside
\draw[fill=blue!50,canvas is xy plane at z=0] (3,0) |- (1,1) |- (0,3) |- cycle;
\draw[fill=blue!30,canvas is xz plane at y=0] (0,0) rectangle (3,1);
\draw[fill=blue!35,canvas is yz plane at x=0] (0,0) rectangle (3,1);
% Outside
\draw[top color=blue!50] {[canvas is yz plane at x=3] (1,0) arc (0:90:1)} -- (0,0,1) --
plot [domain=0:90,samples=21] ({sin(\x)},{sin(\x)},{cos(\x)}) -- cycle;
\draw[top color=blue!60] {[canvas is xz plane at y=3] (1,0) arc (0:90:1)} -- (0,0,1) --
plot [domain=0:90,samples=21] ({sin(\x)},{sin(\x)},{cos(\x)}) -- cycle;
% Grids
\foreach\i in {10,20,...,80}
\draw[opacity=0.2] (3,{cos(\i)},{sin(\i)}) -- ({cos(\i)},{cos(\i)},{sin(\i)}) -- ({cos(\i)},3,{sin(\i)});
\foreach\i in {0.2,0.4,...,2.8}
{
\pgfmathsetmacro\minangle{acos(min(1,\i))}
\draw[canvas is yz plane at x=\i,opacity=0.2] (0,1) arc (90:\minangle:1);
\draw[canvas is xz plane at y=\i,opacity=0.2] (0,1) arc (90:\minangle:1);
}
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{70}{130}
\begin{document}
\begin{tikzpicture}[tdplot_main_coords]
\draw[fill=cyan!50, canvas is xy plane at z=0] (0,0) rectangle (3,1);
\draw[fill=cyan!50, canvas is xy plane at z=0] (0,0) rectangle (1,3);
\shadedraw[top color=cyan, canvas is xz plane at y=0] (0,0) rectangle (3,1);
\shadedraw[top color=cyan, canvas is yz plane at x=0] (0,0) rectangle (3,1);
\shade[inner color=cyan!20, outer color=cyan!70] (3,1,0) {[canvas is yz plane at x=3] arc[radius=1, start angle=0, end angle=90]} -- (0,0,1) -- (0,3,1) {[canvas is xz plane at y=3] arc[radius=1, start angle=90, end angle= 0]} -- (1,1,0) -- cycle;
\begin{scope}
\clip (1,1,-0.5) -- plot[domain=0:90] ({cos(\x)},{cos(\x)},{sin(\x)}) -- (0,0,1.5) -- (3.5,0,1.5) -- (3.5,0,-0.5) -- cycle;
\foreach \x in {0,.15,...,3}
\draw[canvas is yz plane at x=\x] (1,0) arc[radius=1, start angle=0, end angle=90];
\foreach \a in {0,5,...,90}
\draw (0,{cos(\a)},{sin(\a)}) -- (3,{cos(\a)},{sin(\a)});
\end{scope}
\begin{scope}
\clip (1,1,-0.5) -- plot[domain=0:90] ({cos(\x)},{cos(\x)},{sin(\x)}) -- (0,0,1.5) -- (0,3.5,1.5) -- (0,3.5,-0.5) -- cycle;
\foreach \y in {0,.15,...,3}
\draw[canvas is xz plane at y=\y] (1,0) arc[radius=1, start angle=0, end angle=90];
\foreach \a in {0,5,...,90}
\draw ({cos(\a)},0,{sin(\a)}) -- ({cos(\a)},3,{sin(\a)});
\end{scope}
\draw plot[domain=0:90] ({cos(\x)},{cos(\x)},{sin(\x)});
\end{tikzpicture}
\end{document}