关于函数绘图无法编译的问题

发布于 2025-04-29 21:25:44
\documentclass{article}
\usepackage{tikz}

\usepackage[UTF8]{ctex} % 中文支持
\usepackage{tikz-3dplot} % 3D TikZ support
\begin{document}

\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords, scale=1.5]

  \def\R{2}
  \def\H{2}

  % 上下底面圆
  \draw[thick, fill=blue!10, opacity=0.5] 
    (tdplotcs:{\R},{\H},0) arc (0:360:{\R} cm and {\R} cm);
  \draw[thick, fill=blue!10, opacity=0.5] 
    (tdplotcs:{\R},{-\H},0) arc (0:360:{\R} cm and {\R} cm);

  % 竖直圆柱线条
  \foreach \angle in {0,45,...,315}{
    \draw[blue!60]
      (tdplotcs:{\R*cos(\angle)}, {-\H}, {\R*sin(\angle)}) --
      (tdplotcs:{\R*cos(\angle)},  {\H}, {\R*sin(\angle)});}

  % 坐标轴
  \draw[->] (0,0,0) -- (3,0,0) node[below] {$x$};
  \draw[->] (0,0,0) -- (0,3,0) node[above left] {$y$};
  \draw[->, thick] (0,-\H-0.5,0) -- (0,\H+1,0) node[above] {z轴(转轴)}; % 修正中文标签

  % 半径标注
  \draw[red, thick, ->] (0,0,0) -- (\R,0,0) node[below right] {$R$};

\end{tikzpicture}

\end{document}

查看更多

关注者
0
被浏览
54
2 个回答
KnezZz
KnezZz 7小时前
这家伙很懒,什么也没写!
\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage{tikz}
\usetikzlibrary{calc}  % 为了用 \pgfmathsetmacro

\begin{document}
\begin{center}
    
\begin{tikzpicture}[scale=1]
  % ——— 斜投影参数 ———
  % 定义 y 轴对 x 的投影系数 a 和对 y(竖直方向)的系数 b
  \def\a{0.5} % y→x 的投影: (x,y,z)→x + a·y
  \def\b{0.5} % y→y 的投影: (x,y,z)→b·y + z

  % ——— 圆柱参数 ———
  \def\R{2}   % 半径
  \def\H{2}   % 高度一半

  % z 轴标注端点
  \pgfmathsetmacro{\zbot}{-\H-0.5} 
  \pgfmathsetmacro{\ztop}{ \H+0.5}

  % ——— 顶面圆(z=+H) ———
  \draw[thick,fill=blue!10,opacity=0.5]
    plot[domain=0:360,samples=100]
      ({(\R*cos(\x)+\a*\R*sin(\x)) }, {(\b*\R*sin(\x)+\H) })
    -- cycle;

  % ——— 底面圆(z=−H) ———
  \draw[thick,fill=blue!10,opacity=0.5]
    plot[domain=0:360,samples=100]
      ({(\R*cos(\x)+\a*\R*sin(\x)) }, {(\b*\R*sin(\x)-\H) })
    -- cycle;

  % ——— 侧面母线(仅示意四条) ———
  \foreach \t in {0,90,180,270}{
    \pgfmathsetmacro{\xx}{\R*cos(\t)}
    \pgfmathsetmacro{\yy}{\R*sin(\t)}
    \draw[blue!60]
      ({(\xx+\a*\yy) }, {(\b*\yy-\H) }) -- 
      ({(\xx+\a*\yy) }, {(\b*\yy+\H) });
  }

  % ——— 三个坐标轴 ———
  % x 轴
  \draw[->] (0,0) -- (3,0) node[below] {x轴(转轴)};
  % y 轴
  \draw[->] (0,0) -- ({\a*3},{\b*3}) node[above left] {$y$};
  % z 轴(转轴)
  \draw[->,thick] (0,\zbot ) -- (0,\ztop ) node[right] {$z$};

  % ——— 半径 R 标注 ———
  \draw[red,thick,->] (0,0) -- (-\R ,0) node[below right] {$R$};

\end{tikzpicture}

\end{center}
\end{document}
KnezZz
KnezZz 7小时前
这家伙很懒,什么也没写!

5f849afad66193dfbd140b2ea050238b.png
已解决

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览