我对 TikZ 绘制 3D 图形的方式有点小问题。图片中圆柱体顶部和底部的边缘似乎没有正确匹配,尽管我认为我没有犯错。有人知道为什么会这样吗?或者有没有更好的方法来绘制它?(对 TikZ 和 3D 绘图仍然很陌生)
\documentclass[11pt,a4paper,onesided]{report}
\usepackage[ngerman]{babel}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{pgfplots}
\usetikzlibrary{calc,fit,patterns,decorations.markings,matrix,3d}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[thin,->] (-2,0) -- (5,0);
\draw[thin,->] (0,-2) -- (0,3);
%Zylinder
\draw[] (1.5,-1.5) -- (1.5,1.5);
\draw[] (3.5,-1.5) -- (3.5,1.5);
\begin{scope}[canvas is zx plane at y=0]
\draw (0,2.5) circle (2cm);
\draw[fill=gray,opacity=0.5] (0,2.5) circle (1cm);
%
\draw[->] (-2,0) -- (3,0);
\end{scope}
\begin{scope}[canvas is zx plane at y=1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[every node/.append style={
xslant=1,sloped}
]
\node at (2.4,-.2) {\scalebox{1}[.7]{$T_0$}};
\node at (4,.4) {\scalebox{1}[.7]{$T$}};
\node at (-.8,-.2) {\scalebox{1}[.7]{$\mathbb{R}^n$}};
\end{scope}
\end{tikzpicture}
\end{document}
结果:
答案1
这是一个可以产生更令人满意的结果的选项:
代码:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{calc,fit,patterns,decorations.markings,matrix,3d}
\begin{document}
\begin{tikzpicture}[scale=1]
\def\Anglei{-66}
\draw[thin,->] (-2,0) -- (5,0);
\draw[thin,->] (0,-2) -- (0,3);
%Zylinder
\begin{scope}[canvas is zx plane at y=0]
\draw (0,2.5) circle (2cm);
\draw[fill=gray,opacity=0.5] (0,2.5) circle (1cm);
\draw[->] (-2,0) -- (3,0);
\end{scope}
\begin{scope}[canvas is zx plane at y=1.5]
\path (0,2.5) circle (1cm);
\coordinate (circ1a) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circ1b) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\path (0,2.5) circle (1cm);
\coordinate (circ2a) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circ2b) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (circ1a) -- (circ2a);
\draw (circ1b) -- (circ2b);
\end{scope}
\begin{scope}[canvas is zx plane at y=1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[every node/.append style={
xslant=1,sloped}
]
\node at (2.4,-.2) {\scalebox{1}[.7]{$T_0$}};
\node at (4,.4) {\scalebox{1}[.7]{$T$}};
\node at (-.8,-.2) {\scalebox{1}[.7]{$\mathbb{R}^n$}};
\end{scope}
\end{tikzpicture}
\end{document}
这个想法是在圆的适当直径上放置一些辅助坐标;为此,需要适当的角度,正如 Heiko Oberdiek 在his comment
,由于倾斜轴旋转了 45°,所以这个角度是 (90° + 45°)/2 = 67.5°(对符号取模)。
\def\Anglei{-67.5}
\begin{scope}[canvas is zx plane at y=1.5]
\path (0,2.5) circle (1cm);
\coordinate (circ1a) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circ1b) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\path (0,2.5) circle (1cm);
\coordinate (circ2a) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circ2b) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\end{scope}
也许划破一些弧线也是一个好主意:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{calc,fit,patterns,decorations.markings,matrix,3d}
\begin{document}
\begin{tikzpicture}[scale=1]
\def\Anglei{-67.5}
\def\Angleii{233}
\def\Angleiii{170}
\draw[thin,->] (-2,0) -- (5,0);
\draw[thin,->] (0,-2) -- (0,3);
%Zylinder
\begin{scope}[canvas is zx plane at y=0]
\coordinate (circmb) at ( $ (0,2.5) + (\Angleii:2cm) $ );
\coordinate (circma) at ( $ (0,2.5) + (\Angleiii:2cm) $ );
\draw[dashed] (circmb) arc [start angle=\Angleii,end angle=\Angleiii,radius=2cm];
\draw (circma) arc [start angle=\Angleiii,end angle=\Angleii-360,radius=2cm];
\fill[fill=gray,opacity=0.5] (0,2.5) circle (1cm);
\coordinate (circm1) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circm2) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\draw (circm1) arc [start angle=\Anglei,end angle=180+\Anglei,radius=1cm];
\draw[dashed] (circm2) arc [start angle=180+\Anglei,end angle=360+\Anglei,radius=1cm];
\draw[->] (-2,0) -- (3,0);
\end{scope}
\begin{scope}[canvas is zx plane at y=1.5]
\path (0,2.5) circle (1cm);
\coordinate (circ1a) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circ1b) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\path (0,2.5) circle (1cm);
\coordinate (circ2a) at ( $ (0,2.5) + (\Anglei:1cm) $ );
\coordinate (circ2b) at ( $ (0,2.5) + (180+\Anglei:1cm) $ );
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw (circ1a) -- (circ2a);
\draw (circ1b) -- (circ2b);
\end{scope}
\begin{scope}[canvas is zx plane at y=1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\draw (circ2a) arc [start angle=\Anglei,end angle=180+\Anglei,radius=1cm];
\draw[dashed] (circ2b) arc [start angle=180+\Anglei,end angle=360+\Anglei,radius=1cm];
\end{scope}
\begin{scope}[every node/.append style={
xslant=1,sloped}
]
\node at (2.4,-.2) {\scalebox{1}[.7]{$T_0$}};
\node at (4,.4) {\scalebox{1}[.7]{$T$}};
\node at (-.8,-.2) {\scalebox{1}[.7]{$\mathbb{R}^n$}};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
你没有搞错:如果你在直径处取两个环和连接杆,你就会得到这个结果。当你在它们之间再画两条线时,它看起来是这样的:
您也可以考虑使用pgfplots
将圆柱体绘制为表面或线框。您还可以移动线条,使它们位于(cos吨,罪吨) 在里面陣陣-plane 的一些更令人赏心悦目的值吨大于0和π。
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{standalone}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\else
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\fi
\usepackage{pgfplots}
\pgfplotsset{width=\textwidth,compat=1.12}
\usetikzlibrary{calc,fit,patterns,decorations.markings,matrix,3d}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[thin,->] (-2,0) -- (5,0);
\draw[thin,->] (0,-2) -- (0,3);
%Zylinder
\begin{scope}[canvas is xy plane at z=0]
\draw[color=DarkGray] (1.5,-1.5) -- (1.5,1.5);
\draw[color=DarkGray] (3.5,-1.5) -- (3.5,1.5);
\end{scope}
\begin{scope}[canvas is xy plane at z=sqrt(3)/2]
\draw[color=DarkGray] (2,-1.5) -- (2,1.5);
\draw[color=DarkGray] (3,-1.5) -- (3,1.5);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw (0,2.5) circle (2cm);
\draw[fill=gray,opacity=0.5] (0,2.5) circle (1cm);
%
\draw[->] (-2,0) -- (3,0);
\end{scope}
\begin{scope}[canvas is zx plane at y=1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[canvas is zx plane at y=-1.5]
\draw (0,2.5) circle (1cm);
\end{scope}
\begin{scope}[every node/.append style={
xslant=1,sloped}
]
\node at (2.4,-.2) {\scalebox{1}[.7]{$T_0$}};
\node at (4,.4) {\scalebox{1}[.7]{$T$}};
\node at (-.8,-.2) {\scalebox{1}[.7]{$\mathbb{R}^n$}};
\end{scope}
\end{tikzpicture}
\end{document}