# polytopes as inequalities sistem solutions in R3 (x-y-z) cartesian space

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?

• 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

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

\documentclass{minimal}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\tdplotsetmaincoords{70}{120}

\begin{document}
\begin{tikzpicture}[%
tdplot_main_coords,
scale=2,
>=stealth
]
\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;
\end{tikzpicture}
\end{document} 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.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\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;
\end{tikzpicture}

\end{document} maybe this is something that is useful for you purpose. Basically I drew the faces of the polygon in pgfplots

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[view={105}{30}]
(0,0,0)};
(0,1,3) (0,2,0)};
(0,1,3) (2,2,0)};
(2,2,0)};
\addplot3[fill=green,opacity=0.5] coordinates {(0,1,3) (1,0,3) (0,0,3) (0,1,3)};
\end{axis}

\end{tikzpicture}

\end{document} • 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