回転した tikz-3dplot: 表示されている線と隠れた線を自動的に区別するにはどうすればよいですか?

回転した tikz-3dplot: 表示されている線と隠れた線を自動的に区別するにはどうすればよいですか?

そこで、離散化された半球を表す点と三角形要素の図形を生成するスクリプトを用意しました。

ここに画像の説明を入力してください

コードについては以下を参照してください。この半球を描画し、遠近法によって見える線と隠れた線を区別する良い方法はあるでしょうか? ご覧のとおり、ほぼ機能していますが、三角形が解析される順序によるものです。

編集: これですべてのポイントとセルが含まれるようになりました。

\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}

答え1

TeX-SE へようこそ! 可視ライン上の投影に従ってポイントを並べ替える必要があります。嬉しいことに、pgfplotsそれが自動的に行われます。また、データを提供する形式は、ほぼ文字通り適応できます。私が行ったのは、正規表現の検索と置換でデータの繰り返し要素を取り除き、それらをテーブルに入れてプロットすることだけです。上のテーブルは、接続する頂点を指定するプロットの下部に対応し、下のテーブルはこれらの頂点を定義します。

\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}

ここに画像の説明を入力してください

視点を に変更するとview={45}{45}、次のようになります。

ここに画像の説明を入力してください

つまり、既知のビューを調整する自由は保持されますtikz-3dplotが、順序付けは自動的に行われます。

関連情報