12

I want to know if there is a package that automatically draw solids (spheres, cylinders, cubes, prisms).

I know I can do this kind of drawing using TikZ or PSTricks. But what about a package where you can type \cube{2cm} and it draws a cube of side 2 cm.

I am not posting a MWE because I just want to know if such package exists.

10

There is pst-solides3d. The package readme mentions:

The pack­age is de­signed to draw solids in 3D per­spec­tive. Fea­tures in­clude:

  • cre­ate prim­i­tive solids;

  • cre­ate solids by in­clud­ing a list of its ver­tices and faces;

  • faces of solids and sur­faces can be col­ored by choos­ing from a very large palette of col­ors;

  • draw para­met­ric sur­faces in al­ge­braic and re­verse pol­ish no­ta­tion;

  • cre­ate ex­plicit and pa­ram­e­ter­ized al­ge­braic func­tions drawn in 2 or 3 di­men­sions;

  • project text onto a plane and onto the faces of a solid;

  • sup­port for in­clud­ing ex­ter­nal database files.

Here's a small example (compile with LaTeX or XeLaTeX):

enter image description here

\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}
14

You might be interested in asymptote, a vector graphics language that you uses TeX for labels and can be used from within LaTeX.

Asymptote can draw standard shapes (spheres, cylinders, cubes, etc) which you can then scale, rotate, and shift to create many other shapes. (Asymptote can also do many other things.)

Here's a brief example.

\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}

enter image description here

  • Great illustration! Suggestion in constructing s2: use scale(2, 0.5, 0.1). – Charles Staats May 1 '14 at 14:38
  • @mrc WinEdt "asymptote.sty" not found? – Micky K May 1 '14 at 15:51
  • 2
    Actually asymptote.sty should be included in TeX Live, as should the alternative package asypictureB (if your package list was recently updated). – Charles Staats May 1 '14 at 19:20
  • 1
    @CharlesStaats I was unaware for asypictureB . . . I am looking forward to not recompiling figures I haven't changed!. Thanks! – Chris Chudzicki May 2 '14 at 1:32
6

One can also use

   \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}

which gives Formula of the usual solides using tikz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.