Tecnología > Dibujo Técnico
Dibujo de figuras en 3D con LaTeX
(1/1)
Carlos Net:
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) ---% 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}
--- Fin del código ---
Carlos Net:
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: ---% 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}
--- Fin del código ---
Carlos Net:
Una escalera:
--- Código: ---\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}}}
--- Fin del código ---
Carlos Net:
Una escalera doble:
--- Código: ---\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}}}
--- Fin del código ---
Navegación
Ir a la versión completa