我想知道是否有一个可以自动绘制固体(球体、圆柱体、立方体、棱柱体)的包。
我知道我可以使用 TikZ 或 PSTricks 进行此类绘图。但是,如果有一个包可以让你输入文字\cube{2cm}
并绘制一个边长为 2 厘米的立方体,那该怎么办呢?
我没有发布 MWE,因为我只是想知道是否存在这样的包。
答案1
有pst-solides3d
. 软件包自述文件中提到:
该软件包旨在以 3D 透视方式绘制实体。功能包括:
创建原始实体;
通过包含顶点和面的列表来创建实体;
可以从大量颜色中选择,为固体和曲面的表面着色;
用代数和逆波兰符号绘制参数曲面;
创建在二维或三维中绘制的显式和参数化的代数函数;
将文本投影到平面和实体的表面上;
支持包括外部数据库文件。
这是一个小例子(用 LaTeX 或 XeLaTeX 编译):
\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}
\rule[-1cm]{2cm}{2cm} \qquad\qquad
%
\psset{viewpoint=100 30 20,Decran=100,unit=1cm}
\psSolid[object=cube,a=2,
action=draw*,
fillcolor=magenta!20]
\end{document}
答案2
你可能感兴趣渐近线,一种矢量图形语言,使用 TeX 作为标签,并可在 LaTeX 中使用。
Asymptote 可以绘制标准形状(球体、圆柱体、立方体等),然后您可以缩放、旋转和移动这些形状来创建许多其他形状。(Asymptote 还可以做许多其他事情。)
这是一个简单的例子。
\documentclass{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}
import three;
//Setup View
size(200);
currentprojection=orthographic(5,4,2);
//Draw Axes
pen thickblack = black+0.75;
real axislength = 2.0;
draw(L=Label("$x$", position=Relative(1.1), align=SW), -axislength*X--axislength*X,thickblack, Arrow3);
draw(L=Label("$y$", position=Relative(1.1), align=E), -axislength*Y--axislength*Y,thickblack, Arrow3);
draw(L=Label("$z$", position=Relative(1.1), align=N), -2*axislength*Z--2*axislength*Z,thickblack, Arrow3);
//Define cube surfaces
surface c1 = unitcube;
surface c2 = shift(-2Z)*rotate(45,X)*c1;
surface s1 = unitsphere;
surface s2 = rotate(75,Z)*shift(1.5Z)*xscale3(2)*yscale3(0.5)*zscale3(0.1)*s1;
//Draw cube surfaces
draw(c1,palegrey);
draw(c2,green);
draw(s2,red);
\end{asy}
\end{document}
答案3
也可以使用
\documentclass{article}
\textwidth = 19cm
\oddsidemargin = -1.7cm
\evensidemargin = -1.4cm
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{minipage}{0.23 \textwidth}
\begin{center}
\textbf{Le cube}\vskip.3truecm
\begin{tikzpicture}[scale=0.5]
\draw[thick,black] (4,0,0) -- (0,0,0) -- (0,4,0) -- (4,4,0);
\draw[thick,black] (4,0,0) -- (4,0,-4) -- (4,4,-4) -- (4,4,0) -- cycle;
\draw[thick,black](0,4,0) -- (0,4,-4) -- (4,4,-4);
\draw[style=dashed, color=black] (4,0,-4) -- (0,0,-4)-- (0,4,-4);
\draw[style=dashed, color=black] (0,0,0) -- (0,0,-4);
\draw[<->](0,-0.3,0)--(4,-0.3,0);
\draw node[below] at (2,-0.3,0) {c};
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.23\textwidth}
\begin{center}
\textbf{Le pav\'e droit} \\
(parall\'el\'epip\`ede rectangle)\vskip.3truecm
\begin{tikzpicture}[scale=0.5]
\draw[thick,black] (6,0,0) -- (0,0,0) -- (0,3,0) -- (6,3,0);
\draw[thick,black] (6,0,0) -- (6,0,-4) -- (6,3,-4) -- (6,3,0) -- cycle;
\draw[thick,black](0,3,0) -- (0,3,-4) -- (6,3,-4);
\draw[style=dashed, color=black] (6,0,-4) -- (0,0,-4)-- (0,3,-4);
\draw[style=dashed, color=black] (0,0,0) -- (0,0,-4);
\draw[<->](-0.3,0,0)--(-0.3,3,0);
\draw node[left] at (-0.3,1.5,0) {h};
\draw[<->](0,-0.3,0)--(6,-0.3,0);
\draw node[below] at (3,-0.3,0) {L};
\draw[<->](6.3,0,0)--(6.3,0,-4);
\draw node[below right] at (6.3,0,-2) {l};
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.23 \textwidth}
\begin{center}
\textbf{Le prisme droit}\vskip.3truecm
\begin{tikzpicture}[scale=0.5]
\draw[thick,black] (0,5,0)-- (0,0,0) -- (6,0,0)--(6,5,0)--(1,5,-3)--(0,5,0)--(6,5,0);
\draw[style=dashed, color=black] (0,0,0) -- (1,0,-3)-- (1,5,-3);
\draw[style=dashed, color=black] (1,0,-3)-- (6,0,0);
\draw[thick,black] (1.5,0,-2.7) --(1.5,0.5,-2.7)--(1,0.5,-3) ;
\draw[thick,black] (0.9,0,-2.7) --(0.9,0.5,-2.7)--(1,0.5,-3) ;
\draw node[left] at (1,2.5,-3) {h};
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.23 \textwidth}
\begin{center}
\textbf{Le cylindre}\vskip.3truecm
\begin{tikzpicture}[scale=0.8]
\draw[thick,black](3,0,-2) ellipse (1.25 and 0.35);
\draw[thick,black] (1.75,-3,-2) arc (180:360:1.25 and 0.35);
\draw [dashed] (4.25,-3,-2) arc (0:180:1.25 and 0.35);
\draw[style=dashed, color=black](3,-3,-2) -- (4.25,-3,-2);
\draw[style=dashed, color=black](3,0,-2) -- (4.25,0,-2);
\draw node[above left] at (3.7,-0.1,-2) {r};
\draw node[left] at (3,-2,-2) {h};
\draw[thick,black] (1.75,0,-2) --(1.75,-3,-2);
\draw[thick,black] (4.25,0,-2) --(4.25,-3,-2);
\draw[thick,black] (3,-2.8,-2 ) --(3.2,-2.8,-2 ) --(3.2,-3,-2 );
\draw[thick,black, dashed] (3,0,-2)--(3,-3,-2 );
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\vskip1truecm
\begin{minipage}{0.3 \textwidth}
\begin{center}
\textbf{La pyramide} \vskip.3truecm
\begin{tikzpicture}[scale=0.6]
\draw[thick,black] (0,3,0)--(6,3,0)--(6,3,-4);
\draw[style=dashed, color=black](0,3,0) -- (0,3,-4) -- (6,3,-4);
\draw[thick,black] (0,3,0) -- (3,9,-2) -- (6,3,0);
\draw[thick,black] (3,9,-2) -- (6,3,-4);
\draw[style=dashed, color=black](3,9,-2) -- (0,3,-4);
\draw[style=dashed, color=black](3,9,-2) -- (3,3,-2);
\draw[style=dashed, color=black](3,3,-2) -- (6,3,-2);
\draw[thick,black] (3,3.2,-2 ) --(3.2,3.2,-2 ) --(3.2,3,-2 );
\draw node[left] at (3,6,-2) {h};
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.3 \textwidth}
\begin{center}
\textbf{Le c\^one} \vskip.3truecm
\begin{tikzpicture}
\draw[dashed] (0,0) arc (170:10:2cm and 0.4cm)coordinate[pos=0] (a);
\draw[thick,black] (0,0) arc (-170:-10:2cm and 0.4cm)coordinate (b);
\draw[densely dashed] ([yshift=4cm]$(a)!0.5!(b)$) --node[right,font=\footnotesize] {$h$}coordinate[pos=0.95] (aa)($(a)!0.5!(b)$)-- node[above,font=\footnotesize] {$r$}coordinate[pos=0.1] (bb) (b);
\draw[thick,black] (aa) -| (bb);
\draw[thick,black] (a) -- ([yshift=4cm]$(a)!0.5!(b)$) -- (b);
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.3 \textwidth}
\begin{center}
\textbf{La sph\`ere - La boule}\vskip.3truecm
\begin{tikzpicture}
\shade[ball color = gray!40, opacity = 0.4] (0,0) circle (2cm);
\draw[thick,black](0,0) circle (2cm);
\draw[thick,black](-2,0) arc (180:360:2 and 0.6);
\draw[dashed] (2,0) arc (0:180:2 and 0.6);
\fill[fill=black] (0,0) circle (1pt);
\draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
\end{tikzpicture}
\vskip.3truecm$Volume =\dotfill $
\end{center}
\end{minipage}
\end{document}