Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

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}
share|improve this answer

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

share|improve this answer
    
Great illustration! Suggestion in constructing s2: use scale(2, 0.5, 0.1). –  Charles Staats May 1 at 14:38
    
@mrc WinEdt "asymptote.sty" not found? –  SKKhan May 1 at 15:51
1  
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 at 19:20
    
@SKKhan Unfortunately, asymptote is not included in standard TeX distributions. I am not familiar with WinEdt, but if you're interested in trying it out, this page looks helpful: winedt.org/Config/menus/Asymptote.php (Edit: I guess this is not true…see CharlesStaats's comment below.) –  mrc May 1 at 19:23
    
@CharlesStaats I was unaware for asypictureB . . . I am looking forward to not recompiling figures I haven't changed!. Thanks! –  mrc May 2 at 1:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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