所以我有一个脚本,可以生成表示离散半球的点和三角形元素的图形:
请参阅下面的代码。现在我想知道是否有一些好的方法可以绘制这个半球并区分由于透视而产生的可见线和隐藏线?如您所见,它几乎可以正常工作,但仅仅是因为解析三角形的顺序。
编辑:现在所有点和单元格都已包含。
\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
,但排序是自动完成的。