
Como exercício, estou tentando desenhar a interseção do prisma [0,2] x [0,4] x [0,6] e o plano x + y + z = 5.
Meu resultado é:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[x={(-0.45cm,-0.385cm)},y={(1cm,-0.1cm)},z={(0,1cm)}]
\draw [->] (0,0,0) -- (6,0,0) node [below left] {$x$};
\draw [->] (0,0,0) -- (0,6,0) node [right] {$y$};
\draw [->] (0,0,0) -- (0,0,6) node [right] {$z$};
\filldraw [thick, orange, fill opacity=0.3] (0,0,5) -- (0,4,1) -- (1,4,0) -- (2,3,0) -- (2,0,3) -- cycle;
\filldraw [thick, blue, fill opacity=0.2] (2,3,0) -- (2,0,3) -- (5,0,0) -- cycle;
\filldraw [thick, blue, fill opacity=0.2] (1,4,0) -- (0,5,0) -- (0,4,1) -- cycle;
\filldraw [thick, orange, fill opacity=0.3] (2,3,0) -- (2,0,0) -- (2,0,3) -- cycle;
\filldraw [thick, orange, fill opacity=0.3] (1,4,0) -- (0,4,0) -- (0,4,1) --cycle;
\end{tikzpicture}
\end{document}
Eu tenho algumas perguntas agora:
- Acho que há muito código apenas para representar um volume matemático fácil como [0,2] x [0,4] x [0,6]. Existe alguma maneira mais eficiente de desenhá-lo?
- Preciso calcular as interseções manualmente e depois representá-las? Ou existe algum método direto?
- Como posso obter o mesmo resultado usando um
axis
ambiente e\addplot
comandos em vez de\draw
? Já tentei mas sou novo\addplot3
e estou tendo problemas com a posição do eixo (view={}{}
),colormap
não tem uma cor homogênea, a superfície tem uma grade que dificulta a compreensão da imagem e tenho a mesma dúvida nas interseções, faça Preciso calculá-los manualmente?
Prisma completo é:
\draw [fill=orange, fill opacity=0.3] (0,0,6) -- (2,0,6) -- (2,4,6) -- (0,4,6) -- cycle ;
\draw [fill=orange, fill opacity=0.3] (2,0,0) -- (2,0,6) -- (2,4,6) -- (2,4,0) -- cycle ;
\draw [fill=orange, fill opacity=0.3] (2,4,0) -- (0,4,0) -- (0,4,6) -- (2,4,6) -- cycle ;
Responder1
Independentemente do que você faça, considere instalar uma visualização 3D de forma mais sistemática. Talvez a melhor maneira de conseguir isso seja usar o asymptote
, que possui ferramentas para calcular interseções em 3D. Se quiser usar pgfplots
, use patch plots
. No entanto, para isso você mesmo precisa calcular as interseções. Este post é para mencionar algunsTi experimentalkBiblioteca Zo que também permite calcular interseções em 3d.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3dtools}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfdeclarelayer{behind}
\pgfsetlayers{behind,background,main,foreground}
\begin{tikzpicture}[>=stealth,
3d/install view={theta=70,phi=110},
line cap=round,line join=round,
visible/.style={draw,thick,solid},
hidden/.style={draw,very thin,cheating dash},
3d/polyhedron/.cd,fore/.style={visible,fill opacity=0.6},
back/.style={fill opacity=0.6,hidden,3d/polyhedron/complete dashes},
fore layer=foreground,
back layer=background
]
\draw [->] (0,0,0) coordinate (O) -- (6,0,0) coordinate (ex) node [below left] {$x$};
\draw [->] (0,0,0) -- (0,6,0) coordinate (ey) node [right] {$y$};
\draw [->] (0,0,0) -- (0,0,6) coordinate (ez) node [right] {$z$};
\path (5,0,0) coordinate (A) (0,5,0) coordinate (B) (0,0,5) coordinate (C)
(2.5,0,0) coordinate (a) (0,3.5,0) coordinate (b) (0,0,2) coordinate (c) ;
\path[3d/.cd,plane with normal={(ex) through (a) named px},
plane with normal={(ey) through (b) named py},
line through={(A) and (B) named lAB},
line through={(A) and (C) named lAC},
line through={(B) and (C) named lBC}];
\path[3d/intersection of={lAB with px}] coordinate (pABx)
[3d/intersection of={lAB with py}] coordinate (pABy)
[3d/intersection of={lAC with px}] coordinate (pACx)
[3d/intersection of={lBC with py}] coordinate (pBCy);
\pgfmathsetmacro{\mybarycenterA}{barycenter("(A),(pABx),(pACx),(a)")}
\pgfmathsetmacro{\mybarycenterB}{barycenter("(B),(pABy),(pBCy),(b)")}
\tikzset{3d/polyhedron/.cd,O={(\mybarycenterA)},color=blue,
draw face with corners={{(A)},{(pABx)},{(pACx)}},
draw face with corners={{(A)},{(pABx)},{(a)}},
draw face with corners={{(A)},{(a)},{(pACx)}},
O={(\mybarycenterB)},
draw face with corners={{(B)},{(pABy)},{(pBCy)}},
draw face with corners={{(B)},{(pABy)},{(b)}},
draw face with corners={{(B)},{(b)},{(pBCy)}},
color=orange,O={(1,1,1)},
draw face with corners={{(pABx)},{(pACx)},{(C)},{(pBCy)},{(pABy)}},
draw face with corners={{(a)},{(pACx)},{(C)},{(O)}},
draw face with corners={{(b)},{(pBCy)},{(C)},{(O)}},
draw face with corners={{(b)},{(pABy)},{(pABx)},{(a)},{(O)}}
}
\end{tikzpicture}
\end{document}
Ainda há muitos esforços. No entanto, há um benefício: você pode alterar a visualização e ainda assim obter o resultado correto. Por exemplo, para 3d/install view={theta=70,phi=60},
você obterá
Claro, isso também é verdade para soluções asymptote
e patch plot
(talvez exceto pela possibilidade de ter automaticamente as linhas ocultas tracejadas).