我需要帮助来使用 tikz 创建一个漂亮的圆柱体图像/图片,类似于下面的图像。
下面您可以看到我目前的进度,首先是图片,下面是它的代码:
代码:
\documentclass{standalone}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{tikzpicture}
\begin{scope}[x={(.7cm,-.3cm)}]
\path (1,0,0);
\pgfgetlastxy{\cylxx}{\cylxy}
\path (0,1,0);
\pgfgetlastxy{\cylyx}{\cylyy}
\path (0,0,1);
\pgfgetlastxy{\cylzx}{\cylzy}
\pgfmathsetmacro{\cylt}{(\cylzy * \cylyx - \cylzx * \cylyy)/ (\cylzy * \cylxx - \cylzx * \cylxy)}
\pgfmathsetmacro{\ang}{atan(\cylt)}
\pgfmathsetmacro{\ct}{1/sqrt(1 + (\cylt)^2)}
\pgfmathsetmacro{\st}{\cylt * \ct}
\fill[white] (\ct,\st,0) -- ++(0,0,-8) arc[start angle=\ang,delta angle=180,radius=1] -- ++(0,0,8) arc[start angle=\ang+180,delta angle=-180,radius=1];
\begin{scope}[every path/.style={ultra thick}]
\draw (0,0,0) circle[radius=1];
\draw[->] (-3,0,0) -- (5,0,0)node[above] {$\sigma_1$};
\draw[->] (0,-3,0) -- (0,5,0)node[above] {$\sigma_2$};
\draw[->] (0,0,-5) -- (0,0,5)node[above] {$\sigma_3$};
\draw[dashed] (0,0,0) ellipse (1.4cm and 0.8cm);
\draw (\ct,\st,0) -- ++(0,0,-8);
\draw (-\ct,-\st,0) -- ++(0,0,-8);
\draw (\ct,\st,-8) arc[start angle=\ang,delta angle=180,radius=1];
\draw[dashed] (\ct,\st,-8) arc[start angle=\ang,delta angle=-180,radius=1];
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}
到目前为止,我的问题是整个圆柱体和椭圆的方向。如果可能的话,图片中的其他线条也行,但实际上没有必要。
非常感谢您的帮助,并提前致谢。
答案1
第一次尝试,使用 3D。
\documentclass{standalone}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro\raiocilindro{0.5}
\pgfmathsetmacro\anguloInicio{60}
\pgfmathsetmacro\nroRaias{10}
\pgfmathsetmacro\tamanhoSecao{1}
\pgfmathsetmacro\nroSecoes{8}
\begin{scope}[rotate around y =-30]
\begin{scope}[rotate around y =-45]
\begin{scope}[rotate around z =45]
\begin{scope}[rotate around x =45]
\foreach \x in {0,...,\nroSecoes}{
\begin{scope}[shift={(0,0,\tamanhoSecao*\x-0.5*\tamanhoSecao*\nroSecoes)}]
\draw (0,0) ++(\anguloInicio:\raiocilindro) arc (\anguloInicio:\anguloInicio-180:\raiocilindro);
\end{scope}
}
\foreach \x in {1,...,\nroRaias}{
\draw (\anguloInicio-\x*180/\nroRaias:\raiocilindro) ++(0,0,-0.5*\nroSecoes*\tamanhoSecao) -- ++(0,0,\nroSecoes*\tamanhoSecao);
}
\foreach \x in {1,...,\nroRaias}{
\fill[white] (\anguloInicio+\x*180/\nroRaias:\raiocilindro) ++(0,0,-0.5*\nroSecoes*\tamanhoSecao) arc (\anguloInicio+\x*180/\nroRaias:\anguloInicio+\x*180/\nroRaias+180/\nroRaias:\raiocilindro) -- ++(0,0,\nroSecoes*\tamanhoSecao) arc (\anguloInicio+\x*180/\nroRaias+18:\anguloInicio+\x*180/\nroRaias:\raiocilindro) -- ++(0,0,-\nroSecoes*\tamanhoSecao);
\draw (\anguloInicio+\x*180/\nroRaias:\raiocilindro) ++(0,0,-0.5*\nroSecoes*\tamanhoSecao) -- ++(0,0,\nroSecoes*\tamanhoSecao);
}
\foreach \x in {0,...,\nroSecoes}{
\begin{scope}[shift={(0,0,\tamanhoSecao*\x-0.5*\tamanhoSecao*\nroSecoes)}]
\draw (0,0) ++(\anguloInicio:\raiocilindro) arc (\anguloInicio:\anguloInicio+180:\raiocilindro);
\end{scope}
}
\end{scope}
\begin{scope}[rotate around x =90 ]
\pgfmathsetmacro\raioB{\raiocilindro*1.414}
\draw[thick] (0,0) ellipse ({\raiocilindro} and {\raioB});
\end{scope}
\end{scope}
\end{scope}
\draw[blue,-latex] (-3,0,0) -- (3,0,0) node[right] {$\sigma_1$};
\draw[blue,-latex] (0,-3,0) -- (0,3,0) node[right] {$\sigma_3$};
\draw[blue,-latex] (0,0,3) -- (0,0,-3) node[right] {$\sigma_2$};
\node at (3,3,-3) {$\sigma_1 = \sigma_2 = \sigma_3$};
\end{scope}
\end{tikzpicture}
\end{document}