[Tex/LaTex] Draw a prism in TikZ or PSTricks

3dprogrammingpstrickstikz-pgf

Is there a way to define an polygon in plane and output an (orthogonal) prism with that polygon as its base? The prism should be drawn in 3D in parallel oblique perspective with controllable height h, scaling factor k and angle α. Would be great if something like this is possible in TikZ or PSTricks.

So I want a command \prism which takes the list of points (which define the polygon in a plane), α,k and h as an argument and give me the prism as output.

Perhaps I should make clear what I mean by k and α: For example if you draw a cube in 3D you draw one line, then another one in an angle α = 45° but with k = 1/2 the length of the first one etc.

I think this is called parallel oblique projection (α = 45° and k = 1 would be called cavalier projection, α = 63,4° and k=1/2 cabinet projection). Even though it would be interesting for further purposes, I don't want a one-point perspective projection.

Cabinet and Cavalier

In the picture above the lines in the background are not dashed. However I want dashed background lines. If you have a better picture of those projections, feel free to replace it.

Here are some references about projection types:

Best Answer

base contains the list of the x/y polygon coordinates and axe defines the direction vector "x y z" of the prism, which is by default axe=0 0 1

\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}

\psset{unit=0.5,lightsrc=10 5 50,viewpoint=50 20 30 rtp2xyz,Decran=50} 
\begin{pspicture*}(-6,-4)(6,9)               
\psframe(-6,-4)(6,9)          
\psSolid[object=grille,base=-4 4 -4 4,fillcolor=red!30]
\psSolid[object=prisme,h=6,fillcolor=blue!10,
         base=0 1 -1 0 0 -2 1 -1 0 0]
 \axesIIID(4,4,6)(4.5,4.5,8)
\end{pspicture*}
%
\begin{pspicture*}(-6,-4)(6,9)
\psframe(-6,-4)(6,9)
\psSolid[object=grille,base=-4 4 -4 4,fillcolor=red!30]
\psSolid[object=prisme,fillcolor=blue!10,
         axe=0 1 2,h=8,base=0 -2 1 -1 0 0 0 1 -1 0]
\psPoint(0,4.2,8.4){V}
\psline[linecolor=blue,arrowscale=2]{->}(0,0)(V)
\axesIIID(4,4,4)(4.5,4.5,8)
\end{pspicture*}

\end{document}

enter image description here

Simple Boxes with pst-3dplot

\documentclass{article}
\usepackage{pst-3dplot}
\begin{document}   
\psset{coorType=1,Alpha=135}
\begin{pspicture}(-1,-2)(5,2.25)
%\pstThreeDCoor[xMin=-1,xMax=4,yMin=-1,yMax=4,zMin=-1,zMax=4]
\pstThreeDBox[hiddenLine=false](0,0,0)(0,0,3)(3,0,0)(0,3,0)
\end{pspicture}
%
\psset{coorType=2}
\begin{pspicture}(-3,-2)(2,2.25)
%\pstThreeDCoor[xMin=-1,xMax=4,yMin=-1,yMax=4,zMin=-1,zMax=4]
\pstThreeDBox[hiddenLine](0,0,0)(0,0,3)(3,0,0)(0,3,0)
\end{pspicture}

\end{document}

enter image description here

\documentclass{article}
\usepackage{pst-3dplot}
\begin{document}

\psset{coorType=2}
\begin{pspicture}(-2,-2.25)(2,5)
\pstThreeDCoor[xMin=-2,xMax=2,yMin=-2,yMax=5,zMin=-2,zMax=6]
\pstThreeDLine(0,0,0)(0,3,0)(-2,0,0)(0,-3,0)(1,-3,0)(0,0,0)
\pstThreeDLine(1,2,5)(1,5,5)(-1,2,5)(1,-1,5)(2,-1,5)(1,2,5)
\pstThreeDLine(0,0,0)(1,2,5)
\pstThreeDLine(0,3,0)(1,5,5)
\pstThreeDLine[linestyle=dashed](-2,0,0)(-1,2,5)
\pstThreeDLine[linestyle=dashed](0,-3,0)(1,-1,5)
\pstThreeDLine(1,-3,0)(2,-1,5)
\end{pspicture}

\end{document}

enter image description here

and an automatic solution which needs the latest pst-3dplot.tex from http://texnik.dante.de/tex/generic/pst-3dplot/. The Macro \psThreeDPrism will move later to CTAN and also very later I'll realize hidden lines. move=x y is the translation vector for the upper polygon

\documentclass{article}
\usepackage{pst-3dplot}
\begin{document}

\psset{coorType=2}
\begin{pspicture}(-3,-2)(2,5)
\pstThreeDCoor[xMin=-2,xMax=2,yMin=-2,yMax=5,zMin=-2,zMax=7]
\pstThreeDPrism[height=6,move=1 2](0,0,0)(0.5,3,0)(-2,0,0)(0,-3,0)(1,-3,0)(0,0,0)
\end{pspicture}

\end{document}

enter image description here

Related Question