
Als Übung versuche ich, den Schnittpunkt des Prismas [0,2] x [0,4] x [0,6] und der Ebene x + y + z = 5 zu zeichnen.
Mein Ergebnis ist:
\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}
Ich habe jetzt einige Fragen:
- Ich glaube, es gibt eine Menge Code, nur um ein einfaches mathematisches Volumen als [0,2] x [0,4] x [0,6] darzustellen. Gibt es eine effizientere Möglichkeit, es zu zeichnen?
- Muss ich die Schnittpunkte von Hand berechnen und dann darstellen? Oder gibt es eine direkte Methode?
- Wie kann ich dasselbe Ergebnis erzielen, wenn ich eine
axis
Umgebung und\addplot
Befehle anstelle von verwende\draw
? Ich habe es versucht, bin aber neu darin\addplot3
und habe Probleme mit der Achsenposition (view={}{}
),colormap
hat keine homogene Farbe, die Oberfläche hat ein Raster, das das Verständnis des Bildes erschwert, und ich habe dieselben Zweifel bezüglich der Schnittpunkte. Muss ich sie von Hand berechnen?
Vollprisma ist:
\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 ;
Antwort1
Unabhängig davon, was Sie tun, sollten Sie eine 3D-Ansicht systematischer installieren. Der vielleicht beste Weg, dies zu erreichen, ist die Verwendung von asymptote
, das über Tools zum Berechnen von Schnittpunkten in 3D verfügt. Wenn Sie verwenden möchten pgfplots
, verwenden Sie patch plots
. Dafür müssen Sie die Schnittpunkte jedoch immer noch selbst berechnen. In diesem Beitrag werden einigeexperimentelles TikZ-Bibliothekwodurch sich auch Schnittpunkte in 3D berechnen lassen.
\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}
Immer noch viel Aufwand. Es gibt jedoch einen Vorteil: Sie können die Ansicht ändern und erhalten trotzdem das richtige Ergebnis. 3d/install view={theta=70,phi=60},
Sie erhalten beispielsweise
Dies gilt natürlich auch für asymptote
und patch plot
-Lösungen (vielleicht mit Ausnahme der Möglichkeit, die verdeckten Linien automatisch zu stricheln).