Autor Tema: Dibujo de figuras en 3D con LaTeX  (Leído 13614 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Carlos Net

  • Junior
  • ***
  • Mensajes: 89
Dibujo de figuras en 3D con LaTeX
« en: 14/Dic/2015, 11:12:49 am »
Programa en Latex para dibujar figuras en 3D:

 

Documento original: Plane partition

Documento modificado:
  Overleaf Read only
  Overleaf editable


Manual de Tikz: Minimal Tikz

Test:
Código: (latex) [Seleccionar]
% Plane partition
% Author: Jang Soo Kim
% Modified: Carlos at picuino.com

\documentclass{minimal}
\usepackage{tikz}

% The angles of x,y,z-axes
\newcommand\xaxis{210}
\newcommand\yaxis{-30}
\newcommand\zaxis{90}

\definecolor{graytop}{RGB}{160,160,160}
\definecolor{grayleft}{RGB}{192,192,192}
\definecolor{grayright}{RGB}{228,228,228}

% The top side of a cube
\newcommand\topside[3]{
  \fill[fill=graytop, thick, draw=white, shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) --(30:1) --(0,1) --(150:1) --(0,0);
}

% The left side of a cube
\newcommand\leftside[3]{
  \fill[fill=grayleft, thick, draw=white, shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) --(0,-1) --(210:1) --(150:1) --(0,0);
}

% The right side of a cube
\newcommand\rightside[3]{
  \fill[fill=grayright, thick, draw=white, shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) --(30:1) --(-30:1) --(0,-1) --(0,0);
}

% The cube
\newcommand\cube[3]{
  \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}

% Definition of \planepartition
% With three counters
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\newcounter{x}
\newcounter{y}
\newcounter{z}

\newcommand\planepartition[2]{
 \setcounter{x}{-1}
  \foreach \a in {#2} {
    \addtocounter{x}{1}
    \setcounter{y}{-1}
    \foreach \b in \a {
      \addtocounter{y}{1}
      \setcounter{z}{#1}
      \foreach \c in {1,...,\b} {
        \addtocounter{z}{1}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\begin{document}

\begin{tikzpicture}
\planepartition {0}{{3,2,2},{2,2,1},{2,1}}
\planepartition {-7}{{3,3,2},{2,2,2},{2,1,1}}
\end{tikzpicture}

\end{document}

« Última modificación: 14/Dic/2015, 23:18:34 pm por Carlos crawler »

Carlos Net

  • Junior
  • ***
  • Mensajes: 89
Re:Dibujo de figuras en 3D con LaTeX
« Respuesta #1 en: 14/Dic/2015, 22:26:36 pm »
Esta macro permite definir dónde va cada uno de los cubos de la pieza.
En el listado final se debe escribir un 0 o un 1. En caso de escribir 1, se dibuja un cubo.
El orden va de izquierda a derecha, de detras a adelante y de abajo hacia arriba.

Ejemplo: Una banqueta
  Overleaf read only
  Overleaf Edit


Código: [Seleccionar]
% Plane partition
% Author: Jang Soo Kim
% Modified: Carlos at picuino.com

\documentclass{minimal}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{30pt}%
%%%>

% The angles of x,y,z-axes
\newcommand\xaxis{210}
\newcommand\yaxis{-30}
\newcommand\zaxis{90}

\definecolor{graytop}{RGB}{160,160,160}
\definecolor{grayleft}{RGB}{192,192,192}
\definecolor{grayright}{RGB}{228,228,228}

% The top side of a cube
\newcommand\topside[3]{
  \fill[fill=graytop, thick, draw=white, shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) --(30:1) --(0,1) --(150:1) --(0,0);
}

% The left side of a cube
\newcommand\leftside[3]{
  \fill[fill=grayleft, thick, draw=white, shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) --(0,-1) --(210:1) --(150:1) --(0,0);
}

% The right side of a cube
\newcommand\rightside[3]{
  \fill[fill=grayright, thick, draw=white, shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) --(30:1) --(-30:1) --(0,-1) --(0,0);
}

% The cube
\newcommand\cube[3]{
  \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}

% Definition of \planepartition
% With three counters
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\newcounter{x}
\newcounter{y}
\newcounter{z}

\newcommand\planepartition[1]{
  \setcounter{z}{0}
  \foreach \a in {#1} {
     \addtocounter{z}{1}
     \setcounter{y}{0}
     \foreach \b in \a {
       \addtocounter{y}{1}
       \setcounter{x}{0}
       \foreach \c in \b {
         \addtocounter{x}{1}
         \ifnum \c > 0
         \cube{\value{x}}{\value{y}}{\value{z}}
         \fi
      }
    }
  }
}

\begin{document}

\begin{tikzpicture}
\planepartition {
  {{1,0,1},{0,0,0},{1,0,1}},
  {{1,0,1},{0,0,0},{1,0,1}},
  {{1,1,1},{1,1,1},{1,1,1}}}

\end{tikzpicture}

\end{document}
« Última modificación: 14/Dic/2015, 23:29:01 pm por Carlos crawler »

Carlos Net

  • Junior
  • ***
  • Mensajes: 89
Re:Dibujo de figuras en 3D con LaTeX
« Respuesta #2 en: 14/Dic/2015, 23:27:12 pm »
Una escalera:
Código: [Seleccionar]
\planepartition {
  {{1,1,1},{1,1,1},{1,1,1}},
  {{1,1,0},{1,1,0},{1,1,0}},
  {{1,0,0},{1,0,0},{1,0,0}}}

Carlos Net

  • Junior
  • ***
  • Mensajes: 89
Re:Dibujo de figuras en 3D con LaTeX
« Respuesta #3 en: 14/Dic/2015, 23:33:26 pm »
Una escalera doble:

Código: [Seleccionar]
\planepartition {
  {{1,1,1},{1,1,1},{1,1,1}},
  {{1,1,0},{1,1,0},{0,0,0}},
  {{1,0,0},{0,0,0},{0,0,0}}}