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'm here to ask if there's a TikZ/pgf support to draw areas resulting from a system of linear inequalities, into a xyz cartesian space. i found examples of my needs for xy plan at How to plot polygon using TikZ, but i also need to draw some 3d polytopes.

the problem is coordinate system as i found in pgfmanual.pdf seems not suited for R3: only (,) support but i need something like (,,).

As an example, i need to do drawings like this:


but i also need to get a colored surface with a 50% transparent color.

The system which generated that polytope is quite simple and is a linear programming problem:

x_1 + x_2 + x_3 <= 4
x_1 <= 2
x_3 <= 3
3*x_2 + x_3 <= 6
x_1 >= 0
x_2 >= 0
x_3 >= 0

Can you advise me some url/article/doc which can help me, or make me some example to lead me to learn how to reach my target?

Thank you for your attention

share|improve this question
TikZ has a 3D-coordinate system as well, see section 13.2.1, "Canvas, XYZ, and Polar Coordinate Systems" of the PGF (v. 2.10) manual. –  Torbjørn T. Jun 10 '11 at 13:31
add comment

3 Answers

up vote 5 down vote accepted

Just for completeness. In principal the same solution as of Altermundus, but with tikz-3dplot.



    \draw[ultra thick,->] (0,0,0) -- (1,0,0);
    \draw[ultra thick,->] (0,0,0) -- (0,1,0);
    \draw[ultra thick,->] (0,0,0) -- (0,0,1);    
    \draw[fill=gray,opacity=0.5] (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;
    \draw[fill=red,opacity=0.5] (0,2,0) -- (2,2,0) -- (0,1,3) -- cycle;
    \draw[fill=orange,opacity=0.5] (2,2,0) -- (2,0,2) -- (1,0,3) -- (0,1,3) -- cycle;
    \draw[fill=yellow,opacity=0.5] (2,2,0) -- (2,0,0) -- (2,0,2) -- cycle;
    \draw[fill=blue,opacity=0.5] (0,1,3) -- (1,0,3) -- (0,0,3) -- cycle;      

enter image description here

share|improve this answer
add comment

It's possible to draw directly without pgfplots (but this package is very useful) but I think there is no package actually to render polytope directly using mathematical expression of inequalities. There is an answer about Draw a plane with TikZ and there is no package for equalities so no package for inequalities ! I think you need to take a paper and a pencil to make some calculus or perhaps you can look at Asymptote.


\begin{tikzpicture}[x  = {(-0.5cm,-0.5cm)},
                    y  = {(0.9659cm,-0.25882cm)},
                    z  = {(0cm,1cm)},
                    scale = 2]   
\draw[ultra thick,->] (0,0,0) -- (1,0,0);
\draw[ultra thick,->] (0,0,0) -- (0,1,0);
\draw[ultra thick,->] (0,0,0) -- (0,0,1);    
\draw[fill=blue,opacity=0.5] (0,0,0)-- (0,2,0)-- (2,2,0) --(2,0,0)--cycle;
\draw[fill=red,opacity=0.5] (0,2,0)-- (2,2,0)-- (0,1,3)-- cycle;
\draw[fill=orange,opacity=0.5] (2,2,0) --(2,0,2) --(1,0,3)--(0,1,3) --cycle;
\draw[fill=yellow,opacity=0.5] (2,2,0) --(2,0,0) --(2,0,2)-- cycle;
\draw[fill=green,opacity=0.5] (0,1,3)-- (1,0,3)-- (0,0,3)-- cycle;      


enter image description here

share|improve this answer
add comment

maybe this is something that is useful for you purpose. Basically I drew the faces of the polygon in pgfplots



\addplot3[fill=blue,opacity=0.5] coordinates{(0,0,0) (0,2,0) (2,2,0) (2,0,0)
   \addplot3[fill=red,opacity=0.5] coordinates {(0,2,0) (2,2,0)
(0,1,3) (0,2,0)};
\addplot3[fill=orange,opacity=0.5] coordinates {(2,2,0) (2,0,2) (1,0,3)
(0,1,3) (2,2,0)};
\addplot3[fill=yellow,opacity=0.5] coordinates {(2,2,0) (2,0,0) (2,0,2)
\addplot3[fill=green,opacity=0.5] coordinates {(0,1,3) (1,0,3) (0,0,3) (0,1,3)};



enter image description here

share|improve this answer
I may got mixed up with some of the coordinates, but you get the idea :) –  Martin H Jun 10 '11 at 13:41
really thank you. isn't there a way to render the polytope directly using mathematical expression of inequalities? –  Alfatau Jun 10 '11 at 14:03
I am not a math-guru, just an engineer :) There might be a way but pgfplots can plot simple functions and coordinates and is, i think, not meant to work for such things you want to have. Again, this does not mean that there is no way to do it. Couldn't you just generate coordinates for such systems in a more suitable software? –  Martin H Jun 10 '11 at 14:14
Note: pgfplots 1.5.1 has been released recently and its patchplots library comes with a patch type=polygon. This allows to define a geometry of one or more polygons and let pgfplots define the color based on its colormap. It also handles depth information. Compare pgfplots.sourceforge.net/pgfplots.pdf and its section about the patchplots library. –  Christian Feuersänger Jan 5 '12 at 19:00
add comment

Your Answer


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.