Gedrehtes Tikz-3dplot: Wie kann automatisch zwischen sichtbaren und verborgenen Linien unterschieden werden?

Gedrehtes Tikz-3dplot: Wie kann automatisch zwischen sichtbaren und verborgenen Linien unterschieden werden?

Ich habe also ein Skript, das eine Figur aus Punkten und dreieckigen Elementen generiert, die eine diskretisierte Halbkugel darstellt:

Bildbeschreibung hier eingeben

Den Code finden Sie unten. Jetzt frage ich mich, ob es eine gute Möglichkeit gibt, diese Halbkugel zu zeichnen und aufgrund der Perspektive zwischen sichtbaren und verborgenen Linien zu unterscheiden. Wie Sie sehen, funktioniert es fast, aber nur aufgrund der Reihenfolge, in der die Dreiecke analysiert werden.

Bearbeiten: Jetzt sind alle Punkte und Zellen enthalten.

\documentclass{article} 

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

\begin{document}
\tdplotsetmaincoords{60}{125}

%
\pgfmathsetmacro{\rvec}{1.5}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{45}
%
\begin{tikzpicture}[scale=3,tdplot_main_coords]

% Coordinate axes
\draw[thick,->] (0,0,0) -- (-1,0,0) node[anchor=south]{$z$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$x$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$y$};

% Points
\coordinate (p0) at (0,1,0);
\coordinate (p1) at (0,0,-1);
\coordinate (p2) at (-1,0,0);
\coordinate (p3) at (0,0,1);
\coordinate (p4) at (1,0,0);
\coordinate (p5) at (0,0.707107,-0.707107);
\coordinate (p6) at (0.707107,0,-0.707107);
\coordinate (p7) at (0.707107,0.707107,0);
\coordinate (p8) at (-0.707107,0,-0.707107);
\coordinate (p9) at (-0.707107,0.707107,0);
\coordinate (p10) at (-0.707107,0,0.707107);
\coordinate (p11) at (0,0.707107,0.707107);
\coordinate (p12) at (0.707107,0,0.707107);
\coordinate (p13) at (0,0.92388,-0.382683);
\coordinate (p14) at (0.408248,0.816497,-0.408248);
\coordinate (p15) at (0.382683,0.92388,0);
\coordinate (p16) at (0,0.382683,-0.92388);
\coordinate (p17) at (0.408248,0.408248,-0.816497);
\coordinate (p18) at (0.382683,0,-0.92388);
\coordinate (p19) at (0.816497,0.408248,-0.408248);
\coordinate (p20) at (0.92388,0,-0.382683);
\coordinate (p21) at (0.92388,0.382683,0);
\coordinate (p22) at (-0.408248,0.816497,-0.408248);
\coordinate (p23) at (-0.382683,0.92388,0);
\coordinate (p24) at (-0.408248,0.408248,-0.816497);
\coordinate (p25) at (-0.382683,0,-0.92388);
\coordinate (p26) at (-0.816497,0.408248,-0.408248);
\coordinate (p27) at (-0.92388,0,-0.382683);
\coordinate (p28) at (-0.92388,0.382683,0);
\coordinate (p29) at (-0.408248,0.816497,0.408248);
\coordinate (p30) at (0,0.92388,0.382683);
\coordinate (p31) at (-0.816497,0.408248,0.408248);
\coordinate (p32) at (-0.92388,0,0.382683);
\coordinate (p33) at (-0.408248,0.408248,0.816497);
\coordinate (p34) at (-0.382683,0,0.92388);
\coordinate (p35) at (0,0.382683,0.92388);
\coordinate (p36) at (0.408248,0.816497,0.408248);
\coordinate (p37) at (0.408248,0.408248,0.816497);
\coordinate (p38) at (0.382683,0,0.92388);
\coordinate (p39) at (0.816497,0.408248,0.408248);
\coordinate (p40) at (0.92388,0,0.382683);

 % Triangular cells
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p0) -- (p13) -- (p15) -- (p0);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p5) -- (p13) -- (p14) -- (p5);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p13) -- (p14) -- (p15) -- (p13);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p7) -- (p14) -- (p15) -- (p7);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p1) -- (p16) -- (p18) -- (p1);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p5) -- (p16) -- (p17) -- (p5);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p16) -- (p17) -- (p18) -- (p16);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p6) -- (p17) -- (p18) -- (p6);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p5) -- (p17) -- (p14) -- (p5);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p6) -- (p17) -- (p19) -- (p6);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p17) -- (p19) -- (p14) -- (p17);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p7) -- (p19) -- (p14) -- (p7);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p4) -- (p20) -- (p21) -- (p4);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p6) -- (p20) -- (p19) -- (p6);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p20) -- (p19) -- (p21) -- (p20);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p7) -- (p19) -- (p21) -- (p7);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p0) -- (p13) -- (p23) -- (p0);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p5) -- (p13) -- (p22) -- (p5);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p13) -- (p22) -- (p23) -- (p13);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p9) -- (p22) -- (p23) -- (p9);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p1) -- (p16) -- (p25) -- (p1);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p5) -- (p16) -- (p24) -- (p5);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p16) -- (p24) -- (p25) -- (p16);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p8) -- (p24) -- (p25) -- (p8);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p5) -- (p24) -- (p22) -- (p5);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p8) -- (p24) -- (p26) -- (p8);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p24) -- (p26) -- (p22) -- (p24);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p9) -- (p26) -- (p22) -- (p9);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p2) -- (p27) -- (p28) -- (p2);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p8) -- (p27) -- (p26) -- (p8);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p27) -- (p26) -- (p28) -- (p27);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p9) -- (p26) -- (p28) -- (p9);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p0) -- (p23) -- (p30) -- (p0);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p9) -- (p23) -- (p29) -- (p9);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p23) -- (p29) -- (p30) -- (p23);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p11) -- (p29) -- (p30) -- (p11);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p2) -- (p28) -- (p32) -- (p2);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p9) -- (p28) -- (p31) -- (p9);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p28) -- (p31) -- (p32) -- (p28);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p10) -- (p31) -- (p32) -- (p10);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p9) -- (p31) -- (p29) -- (p9);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p10) -- (p31) -- (p33) -- (p10);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p31) -- (p33) -- (p29) -- (p31);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p11) -- (p33) -- (p29) -- (p11);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p3) -- (p34) -- (p35) -- (p3);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p10) -- (p34) -- (p33) -- (p10);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p34) -- (p33) -- (p35) -- (p34);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p11) -- (p33) -- (p35) -- (p11);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p0) -- (p30) -- (p15) -- (p0);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p11) -- (p30) -- (p36) -- (p11);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p30) -- (p36) -- (p15) -- (p30);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p7) -- (p36) -- (p15) -- (p7);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p3) -- (p35) -- (p38) -- (p3);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p11) -- (p35) -- (p37) -- (p11);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p35) -- (p37) -- (p38) -- (p35);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p12) -- (p37) -- (p38) -- (p12);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p11) -- (p37) -- (p36) -- (p11);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p12) -- (p37) -- (p39) -- (p12);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p37) -- (p39) -- (p36) -- (p37);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p7) -- (p39) -- (p36) -- (p7);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p4) -- (p40) -- (p21) -- (p4);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p12) -- (p40) -- (p39) -- (p12);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p40) -- (p39) -- (p21) -- (p40);
\draw[fill=green,draw=black,opacity=.8,very thin,line join=round] (p7) -- (p39) -- (p21) -- (p7);


\end{tikzpicture}
\end{document}

Antwort1

Willkommen bei TeX-SE! Sie müssen die Punkte entsprechend ihrer Projektion auf die Sichtbarkeitslinie sortieren. Die gute Nachricht ist, dass pgfplotsdas für Sie erledigt wird. Und das Format, das Sie den Daten bereitstellen, kann fast wörtlich angepasst werden. Ich habe lediglich mit regulären Ausdrücken gesucht und ersetzt, um die sich wiederholenden Elemente Ihrer Daten zu entfernen, sie in Tabellen zu setzen und sie darzustellen. Die obere Tabelle entspricht dem unteren Teil Ihres Diagramms, in dem Sie angeben, welche Eckpunkte verbunden werden sollen, und die untere Tabelle definiert diese Eckpunkte.

\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={135}{45},axis equal image,scale=4,
xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=-1,zmax=1,
colormap={greenblue}{color=(green) color=(blue)}]
\addplot3 [patch,table/row sep=\\,patch table={
0 13 15 \\
5 13 14 \\
13 14 15 \\
7 14 15 \\
1 16 18 \\
5 16 17 \\
16 17 18 \\
6 17 18 \\
5 17 14 \\
6 17 19 \\
17 19 14 \\
7 19 14 \\
4 20 21 \\
6 20 19 \\
20 19 21 \\
7 19 21 \\
0 13 23 \\
5 13 22 \\
13 22 23 \\
9 22 23 \\
1 16 25 \\
5 16 24 \\
16 24 25 \\
8 24 25 \\
5 24 22 \\
8 24 26 \\
24 26 22 \\
9 26 22 \\
2 27 28 \\
8 27 26 \\
27 26 28 \\
9 26 28 \\
0 23 30 \\
9 23 29 \\
23 29 30 \\
11 29 30 \\
2 28 32 \\
9 28 31 \\
28 31 32 \\
10 31 32 \\
9 31 29 \\
10 31 33 \\
31 33 29 \\
11 33 29 \\
3 34 35 \\
10 34 33 \\
34 33 35 \\
11 33 35 \\
0 30 15 \\
11 30 36 \\
30 36 15 \\
7 36 15 \\
3 35 38 \\
11 35 37 \\
35 37 38 \\
12 37 38 \\
11 37 36 \\
12 37 39 \\
37 39 36 \\
7 39 36 \\
4 40 21 \\
12 40 39 \\
40 39 21 \\
7 39 21 \\
}] table [row sep=\\,point meta=\thisrow{c}] {
 x y z c\\
 0 1 0 0\\
 0 0 -1 0\\
 -1 0 0 0\\
 0 0 1 0\\
 1 0 0 0\\
 0 0.707107 -0.707107 0\\
 0.707107 0 -0.707107 0\\
 0.707107 0.707107 0 0\\
 -0.707107 0 -0.707107 0\\
 -0.707107 0.707107 0 0\\
 -0.707107 0 0.707107 0\\
 0 0.707107 0.707107 0\\
 0.707107 0 0.707107 0\\
 0 0.92388 -0.382683 0\\
 0.408248 0.816497 -0.408248 0\\
 0.382683 0.92388 0 0\\
 0 0.382683 -0.92388 0\\
 0.408248 0.408248 -0.816497 0\\
 0.382683 0 -0.92388 0\\
 0.816497 0.408248 -0.408248 0\\
 0.92388 0 -0.382683 0\\
 0.92388 0.382683 0 0\\
 -0.408248 0.816497 -0.408248 0\\
 -0.382683 0.92388 0 0\\
 -0.408248 0.408248 -0.816497 0\\
 -0.382683 0 -0.92388 0\\
 -0.816497 0.408248 -0.408248 0\\
 -0.92388 0 -0.382683 0\\
 -0.92388 0.382683 0 0\\
 -0.408248 0.816497 0.408248 0\\
 0 0.92388 0.382683 0\\
 -0.816497 0.408248 0.408248 0\\
 -0.92388 0 0.382683 0\\
 -0.408248 0.408248 0.816497 0\\
 -0.382683 0 0.92388 0\\
 0 0.382683 0.92388 0\\
 0.408248 0.816497 0.408248 0\\
 0.408248 0.408248 0.816497 0\\
 0.382683 0 0.92388 0\\
 0.816497 0.408248 0.408248 0\\
 0.92388 0 0.382683 0\\
 };
\end{axis}
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

Wenn Sie die Ansicht ändern view={45}{45}, erhalten Sie

Bildbeschreibung hier eingeben

Das heißt, Sie behalten die gewohnte Freiheit bei der Anpassung der Ansicht, tikz-3dplotdie Sortierung erfolgt jedoch automatisch.

verwandte Informationen