3

I am computing the coordinates of a circuit on the sphere using several (heavy) pgfmath macros. This results in a costly production of what is basically a table of two dimensional coordinates.

Using commands like

\draw[green] plot file {foo.table};

I can produce the contour of this picture (the solide line).Contour and folded surface attached to a point

But to produce the folded area attached to the center of the sphere, I need to use the data computed by pgfmath directly in a loop and store the position of the point number n to plot the point number n+1 (the area is made of triangles drawn with the options opacity=0.5 to give the expected volume effect).

How could I use the file foo.table to draw the triangles ?

Here is the code of a MWE containing the coordinates of the contour.

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

That's actually a duplicate of Drawing a 3D cone. But it's a fun duplicate, and some changes are required to have the result look similar to what you want. For example:

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

Output:

output

  • Wow ! Thank you so much for this very good answer. This is exactly what I wanted. – Tom-Tom Nov 26 '15 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.