我正在使用几个(繁重的)宏来计算球体上电路的坐标pgfmath
。这导致生成基本上是二维坐标表的成本高昂。
使用类似命令
\draw[green] plot file {foo.table};
但是为了产生连接到球体中心的折叠区域,我需要pgfmath
在循环中直接使用计算的数据并存储点号的位置n
以绘制点号n+1
(该区域由使用选项绘制的三角形组成,opacity=0.5
以提供预期的体积效果)。
我如何使用该文件foo.table
绘制三角形?
这是包含轮廓坐标的 MWE 代码。
\documentclass{article}
\usepackage{filecontents}
\usepackage{tikz}
\begin{filecontents}{foo.table}
-2.29732 0.562597
-2.46077 0.625805
-2.57584 0.71416
-2.63998 0.816141
-2.66182 0.920619
-2.65234 1.02147
-2.62076 1.11484
-2.57249 1.19958
-2.51155 1.27533
-2.43976 1.34266
-2.3593 1.40214
-2.27191 1.45466
-2.18021 1.50059
-2.08669 1.54079
-1.99478 1.57552
-1.90685 1.60501
-1.82599 1.63018
-1.75452 1.65186
-1.69393 1.67119
-1.64512 1.68957
-1.60823 1.709
-1.58249 1.73134
-1.56535 1.75887
-1.55367 1.79362
-1.54343 1.83718
-1.53004 1.89022
-1.50929 1.95238
-1.47762 2.02234
-1.43256 2.09793
-1.37379 2.17617
-1.3026 2.25408
-1.22121 2.32878
-1.13342 2.39764
-1.04333 2.45867
-0.955271 2.51064
-0.873334 2.55296
-0.800973 2.58505
-0.740967 2.60705
-0.694815 2.61903
-0.663029 2.621
-0.645284 2.61303
-0.640066 2.59519
-0.645636 2.56722
-0.659579 2.52956
-0.679626 2.48256
-0.703663 2.42761
-0.729928 2.36629
-0.756862 2.3006
-0.783243 2.23337
-0.808042 2.16758
-0.830145 2.10622
-0.848038 2.0521
-0.860296 2.00728
-0.865032 1.97321
-0.86053 1.95058
-0.845243 1.93878
-0.818525 1.93681
-0.780152 1.94306
-0.730695 1.95537
-0.671749 1.97182
-0.604967 1.98989
-0.53254 2.00757
-0.456746 2.02293
-0.379503 2.03405
-0.302492 2.03917
-0.227065 2.03719
-0.154141 2.02689
-0.0846459 2.00691
-0.0194568 1.97702
0.0402252 1.9364
0.0927954 1.88509
0.136014 1.82341
0.166822 1.75208
0.182072 1.67283
0.177692 1.58763
0.150057 1.49981
0.0962308 1.41353
0.0152284 1.33285
-0.0912037 1.26258
-0.218461 1.20699
-0.358397 1.16837
-0.50119 1.14729
-0.637133 1.14165
-0.758478 1.14754
-0.860913 1.15971
-0.943287 1.17277
-1.0075 1.18142
-1.05683 1.18161
-1.0954 1.17012
-1.1276 1.14484
-1.15794 1.10468
-1.19054 1.05006
-1.23024 0.982231
-1.28177 0.903583
-1.35095 0.818083
-1.44357 0.731335
-1.5653 0.650635
-1.71889 0.5845
-1.90224 0.542744
-2.10245 0.534021
-2.29732 0.562597
\end{filecontents}
\begin{document}
\tikz{
\draw circle(3);
\node {$\bullet$};
\draw[green] plot file {foo.table};
}
\end{document}
答案1
这实际上是绘制 3D 圆锥体。但这是一个有趣的复制,需要进行一些更改才能使结果看起来与您想要的相似。例如:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{
to center/.style={
decorate,
decoration={show path construction,
lineto code={
\path [fill=green!20,opacity=0.5,line join=round]
(\tikzinputsegmentlast) -- (\tikzinputsegmentfirst)
-- (center) -- cycle;
}}}}
\begin{document}
\begin{tikzpicture}
\draw circle(3);
\coordinate (center) at (0,0);
\node at (center) {$\bullet$};
\fill [green!30, to center]
plot file {foo.table} -- cycle;
\draw[green] plot file {foo.table};
\end{tikzpicture}
\end{document}
输出: