如何在 LaTeX 中写出等腰三棱柱?

如何在 LaTeX 中写出等腰三棱柱?

我想在 LateX 中制作这个图形并标记矩形的宽度。

在此处输入图片描述

我知道 Tikz 是必需的,而且我应该使用该\draw命令,但这就是我所知道的全部。

答案1

您可以在 tikz 中制作棱镜,使用轴设置进行散点透视,并借助3dcalc库。在下面的代码中,我首先设置所有点的坐标,其余的是“连接点”。

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usetikzlibrary{3d}   % for "canvas is..." option
\usetikzlibrary{calc} % for calculate some coordinates

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,
  x={(-0.5cm,-0.5cm)},y={(1cm,0cm)},z={(0cm,1cm)}, % cavalier axes
  ]
  \def\b{3}
  \def\L{4}
  \def\a{40} % angle between equal sides
  \foreach\i in {0,1}
  {% coordinates and fillings
    \begin{scope}[canvas is yz plane at x=-\L*\i]
      \coordinate (A\i) at (0,0);
      \coordinate (B\i) at (-\b,0);
      \coordinate (C\i) at (180-\a:\b);
      \coordinate (D\i) at ({-\b*cos(\a)},0); % bottom of the height h
      \fill[red,opacity=0.1] (A\i) -- (B\i) -- (C\i) -- cycle;
    \end{scope}
  }
  % lines
  \draw[gray,dashed] (B0) -- (B1);
  \draw[gray,dashed] (A1) -- (B1) -- (C1);
  \draw[red,canvas is yz plane at x=0]
        ($(D0)+(0,0.2)$) -| ($(D0)+(0.2,0)$); % right angle
  \draw (D0) -- (C0) -- (C1) -- (A1) -- (A0) -- (B0) -- (C0) -- (A0);
  % labels
  \node at ($(A0)!0.5!(B0)$) [below] {$b$};
  \node at ($(C0)!0.7!(D0)$) [right] {$h$};
  \node at ($(C0)!0.4!(C1)$) [above] {$L$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

感谢 mamor 对本回答的支持。您可以3dtool使用这里

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools

\begin{document}
    \pgfdeclarelayer{background}
    \pgfdeclarelayer{foreground} 
    \pgfsetlayers{background,main,foreground}
    \foreach \Angle in  {5,10,...,355}
    {\begin{tikzpicture}[same bounding box=A,line cap=round,line join=round, 
            3d/install view={phi=\Angle,psi=0,theta=70},
            declare function={a=2;b=6;h=3;}, c/.style={circle,fill,inner sep=1pt}]
            \path
            (-2*a,0,0) coordinate (A)
            (a,0,0) coordinate (B)
            (a,b,0) coordinate (C)
            (-2*a,b,0) coordinate (D)
            (0,0,h) coordinate (M)
            (0,b,h) coordinate (N);
            \pgfmathsetmacro{\mybarycenter}{barycenter("(A),(B),(C),(D),(M),(N)")}
            \path (\mybarycenter) coordinate (T);
            \tikzset{3d/line through={(A) and (B) named lAB}} 
            \path[3d/project={(M) on lAB}] coordinate (H);
            \tikzset{3d/polyhedron/.cd,O={(T)},
                edges have complete dashes,
                back layer=background,
                fore/.append style={fill=pink},
                back/.append style={draw=none,fill=pink,fill opacity=1},
                draw face with corners={{(A)},{(M)},{(H)}},
                draw face with corners={{(B)},{(M)},{(H)}},
                draw face with corners={{(D)},{(C)},{(N)}},
                fore/.append style={fill=none},
                back/.append style={fill=none},
                draw face with corners={{(C)},{(N)},{(M)},{(B)}},
                draw face with corners={{(N)},{(D)},{(A)},{(M)}}
            }
            %\path foreach \p/\g in {A/90,B/90,C/0,D/90,M/90,N/90,H/0}{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
                    \end{tikzpicture}}
\end{document}      

在此处输入图片描述

相关内容