圆柱坐标图

圆柱坐标图

我想知道如何仅使用以下方法绘制这个 3D 对象tikz-3dplot

在此处输入图片描述

答案1

欢迎!感谢您的澄清!以下允许您指定ab以及物体的高度h。这是通过定义函数并在参数图中绘制它们来实现的。可见角度,即实线变为虚线的点,是通过数字计算的。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{40}
\begin{tikzpicture}[tdplot_main_coords,line join=round,line cap=round,
    >=stealth,declare function={R(\t)=sqrt(abs(cos(2*(\t))));
    a=3;b=2;h=3;}]
 \draw[->] (-4,0,0) -- (4,0,0) node[pos=1.05]{$x$};
 \draw[->] (0,-4,0) -- (0,4,0) node[pos=1.05]{$y$};
 \draw[->] (0,0,0) -- (0,0,4) node[pos=1.05]{$z$};
 \edef\myt{-45} 
 \edef\mytcrit{-45}
 \edef\myxmax{0pt}
 \loop
 \path[overlay] ({a*R(\myt)*cos(\myt)},{b*R(\myt)*sin(\myt)},0) coordinate(aux);    
 \pgfpointanchor{aux}{center}%
 \pgfgetlastxy{\myx}{\myy}%
 \ifdim\myx>\myxmax
  \edef\mytcrit{\myt}%
  \edef\myxmax{\myx}%
 \fi
 \ifnum\myt<45
 \edef\myt{\the\numexpr\myt+1}
 \repeat    
 \draw[densely dashed] plot[variable=\t,domain=\mytcrit:45,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},0);
 \draw[densely dashed] plot[variable=\t,domain=-45:\mytcrit,smooth]
    ({-a*R(\t)*cos(\t)},{-b*R(\t)*sin(\t)},0);
 \draw plot[variable=\t,domain=-45:\mytcrit,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},0);
 \draw plot[variable=\t,domain=\mytcrit:45,smooth]
    ({-a*R(\t)*cos(\t)},{-b*R(\t)*sin(\t)},0);
 \draw ({a*R(\mytcrit)*cos(\mytcrit)},{b*R(\mytcrit)*sin(\mytcrit)},0)
 -- ({a*R(\mytcrit)*cos(\mytcrit)},{b*R(\mytcrit)*sin(\mytcrit)},h)
 ({-a*R(\mytcrit)*cos(\mytcrit)},{-b*R(\mytcrit)*sin(\mytcrit)},0)
 -- ({-a*R(\mytcrit)*cos(\mytcrit)},{-b*R(\mytcrit)*sin(\mytcrit)},h);
 \draw plot[variable=\t,domain=-45:45,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},h);
 \draw plot[variable=\t,domain=-45:45,smooth]
    ({-a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},h);
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者外表坚实。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{40}
\begin{tikzpicture}[tdplot_main_coords,line join=round,line cap=round,
    >=stealth,declare function={R(\t)=sqrt(abs(cos(2*(\t))));
    a=3;b=2;h=3;}]
 \draw[->] (-4,0,0) -- (4,0,0) node[pos=1.05]{$x$};
 \draw[->] (0,-4,0) -- (0,4,0) node[pos=1.05]{$y$};
 \draw[->] (0,0,0) -- (0,0,4) node[pos=1.05]{$z$};
 \edef\myt{-45} 
 \edef\mytcrit{-45}
 \edef\myxmax{0pt}
 \loop
 \path[overlay] ({a*R(\myt)*cos(\myt)},{b*R(\myt)*sin(\myt)},0) coordinate(aux);    
 \pgfpointanchor{aux}{center}%
 \pgfgetlastxy{\myx}{\myy}%
 \ifdim\myx>\myxmax
  \edef\mytcrit{\myt}%
  \edef\myxmax{\myx}%
 \fi
 \ifnum\myt<45
 \edef\myt{\the\numexpr\myt+1}
 \repeat    
 \draw[densely dashed] plot[variable=\t,domain=\mytcrit:45,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},0);
 \draw[densely dashed] plot[variable=\t,domain=-45:\mytcrit,smooth]
    ({-a*R(\t)*cos(\t)},{-b*R(\t)*sin(\t)},0);
 \draw[left color=gray,right color=gray!80,middle color=gray!20,fill opacity=0.6] 
  plot[variable=\t,domain=-45:\mytcrit,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},0)
    -- plot[variable=\t,domain=\mytcrit:-45,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},h) --cycle;
 \draw[left color=gray!70!black,right color=gray!80,middle color=gray!50,fill opacity=0.6] plot[variable=\t,domain=\mytcrit:45,smooth]
    ({-a*R(\t)*cos(\t)},{-b*R(\t)*sin(\t)},0)
    -- plot[variable=\t,domain=45:\mytcrit,smooth]
    ({-a*R(\t)*cos(\t)},{-b*R(\t)*sin(\t)},h) -- cycle;
 \draw[fill=gray,fill opacity=0.6] plot[variable=\t,domain=-45:45,smooth]
    ({a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},h);
 \draw[fill=gray,fill opacity=0.6] plot[variable=\t,domain=-45:45,smooth]
    ({-a*R(\t)*cos(\t)},{b*R(\t)*sin(\t)},h);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容