我怎样才能用 3D 方式绘制这个圆柱体?

我怎样才能用 3D 方式绘制这个圆柱体?

我正在尝试画这个圆柱体。 在此处输入图片描述

我用过tkz-euclide。我的代码

\documentclass[border=2mm,12pt]{standalone}
\usepackage{fouriernc}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{shadings}
\begin{document}
\begin{tikzpicture}
\def\R{2}
\def\a{0.5}
\def\h{2*\R}
(\R,0) -- (\R,\h)  arc (360:180:\R cm and \a cm)
          -- (-\R,0) arc (180:360:\R cm and \a cm);

(0,\h) circle (\R cm and \a cm);
  \draw[thick] (-\R,\h) -- (-\R,0) arc (180:360:\R cm and \a cm)-- (\R,\h) ++ (-\R,0) circle (\R cm and \a cm);
  \draw[dashed] (-\R,0) arc (180:0:\R cm and \a cm);
\coordinate (O) at (0,0);
\coordinate (O') at ($(O)+(0,\h)$);
\coordinate (A) at (\R,0);
\coordinate (B) at ($(O) + (-70:{\R} and {\a})$);
\coordinate (A') at ($(A)+(0,\h)$);
\coordinate (B') at ($(B)+(0,\h)$);
\tkzFillPolygon[pattern=north west lines](A,B,B',A')
\tkzDrawPoints[fill = black,size = 5 pt](A,B,O,O',A',B')
\tkzLabelPoints[right](A,A')
\tkzLabelPoints[below](B)
\tkzLabelPoints[above](B')
\tkzLabelPoints[left](O,O')
\tkzDrawSegments[dashed](A,B  O,O')
\tkzDrawSegments[thick](B,B' B',A')
 \end{tikzpicture}
\end{document}

我怎样才能用 来绘制它tikz-3dplot

答案1

像这样吗?

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\usepackage{fouriernc}
\begin{document}
\def\myr{3}
\def\h{6}
\def\angA{0}
\def\angB{80}
\tdplotsetmaincoords{80}{60}
\begin{tikzpicture}[tdplot_main_coords]
%    \draw[-latex] (0,0,0) -- (1,0,0) node[pos=1.1]{$x$};
%    \draw[-latex] (0,0,0) -- (0,1,0) node[pos=1.1]{$y$};
%    \draw[-latex] (0,0,0) -- (0,0,1) node[pos=1.1]{$z$};
  \begin{scope}[canvas is xy plane at z=0]
   \path (0,0) coordinate[label=below:$O$] (O);
   \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
   \draw[dashed] (\angA:\myr) coordinate (A) -- (\angB:\myr) coordinate (B)
    node[pos=-0.1] {$A$} node[pos=1.1] {$B$};
   \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
   coordinate(BL);
  \end{scope}
  %
  \begin{scope}[canvas is xy plane at z=\h]
   \draw[thick] (0,0) coordinate[label=above:$O'$] (O') circle[radius=\myr];
   \draw[dashed] (O) -- (O');
   \draw[thick] (\angA:\myr) coordinate (A') -- (\angB:\myr) coordinate (B')
    node[pos=-0.1] {$A'$} node[pos=1.1] {$B'$};
   \path[pattern=north east lines] (A) -- (B) -- (B') -- (A') -- cycle;
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angA-\tdplotmainphi))}
   \draw (BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr);
   \ifnum\itest=-1
    \draw[dashed] (A) -- (A');
   \else
    \draw[thick] (A) -- (A');
   \fi
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angB-\tdplotmainphi))}
   \ifnum\itest=-1
    \draw[dashed] (B) -- (B');
   \else
    \draw[thick] (B) -- (B');
   \fi
  \end{scope}
  \foreach \X in {A,B,O}
  {\fill (\X) circle(1pt) (\X') circle(1pt);}
\end{tikzpicture}
\end{document} 

在此处输入图片描述

如果平面的垂直边界位于圆柱体的背面,则其为虚线。

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,calc,backgrounds,patterns}
\usepackage{fouriernc}
\begin{document}
\def\myr{3}
\def\h{6}
\def\angA{0}
\def\angB{80}
\foreach \X in {0,10,...,350}
{\tdplotsetmaincoords{80}{\X}
\begin{tikzpicture}[tdplot_main_coords]
\path[tdplot_screen_coords,use as bounding box] (-1.3*\myr,-1) rectangle 
(1.3*\myr,\h+1);
%    \draw[-latex] (0,0,0) -- (1,0,0) node[pos=1.1]{$x$};
%    \draw[-latex] (0,0,0) -- (0,1,0) node[pos=1.1]{$y$};
%    \draw[-latex] (0,0,0) -- (0,0,1) node[pos=1.1]{$z$};
  \begin{scope}[canvas is xy plane at z=0]
   \path (0,0) coordinate[label=below:$O$] (O);
   \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
   \draw[dashed] (\angA:\myr) coordinate (A) -- (\angB:\myr) coordinate (B)
    node[pos=-0.1] {$A$} node[pos=1.1] {$B$};
   \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr)
   coordinate(BL);
  \end{scope}
  %
  \begin{scope}[canvas is xy plane at z=\h]
   \draw[thick] (0,0) coordinate[label=above:$O'$] (O') circle[radius=\myr];
   \draw[dashed] (O) -- (O');
   \draw[thick] (\angA:\myr) coordinate (A') -- (\angB:\myr) coordinate (B')
    node[pos=-0.1] {$A'$} node[pos=1.1] {$B'$};
   \path[pattern=north east lines] (A) -- (B) -- (B') -- (A') -- cycle;
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angA-\tdplotmainphi))}
   \draw (BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr);
   \ifnum\itest=-1
    \draw[dashed] (A) -- (A');
   \else
    \draw[thick] (A) -- (A');
   \fi
   \pgfmathtruncatemacro{\itest}{-sign(sin(\angB-\tdplotmainphi))}
   \ifnum\itest=-1
    \draw[dashed] (B) -- (B');
   \else
    \draw[thick] (B) -- (B');
   \fi
  \end{scope}
  \foreach \X in {A,B,O}
  {\fill (\X) circle(1pt) (\X') circle(1pt);}
\end{tikzpicture}}
\end{document} 

在此处输入图片描述

相关内容