2

I try to create a shaded area inside six paths. I tried to follow this answer where the package spath3 had been used.

As you can see in the first picture it works like desired, when I know the explicit coordinates of the paths. However, my real life issue includes a rotation and shift in scope enviroments, which is shown in the second and third example and somehow hinder the incorporation of this method. Unfortunately, I could only create a similar, not an identical figure for the scope environment example.

Is there any solution how to create a shaded area while using scope environment? I am not necessarily restricted to the package spath3. Thank you very much.

Shading - spath3 with exact coordinates

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{spath3,intersections,hobby}

\ExplSyntaxOn

\cs_set_eq:NN \getComponentOf \clist_item:Nn

\ExplSyntaxOff

\tikzset{ % from texexchange: transform defined coordinates in TikZ c/.style={every coordinate/.try} }

\begin{document}

\begin{tikzpicture}[very thick, every node/.style={scale=10}, scale=13]

 \draw[spath/save=orange, orange] (3,1)  -- (6,4) ;
 \draw[spath/save=blue, blue] (1,4) -- (4,1) ;
 \draw[spath/save=red, red] (0.5,2.5)  --  (3.5,6) ;    
 \draw[spath/save=lime, lime] (2,2)  --  (2,5) ;
 \draw[spath/save=green, green] (6,2.6)  --  (2.5,6) ;
 \draw[spath/save=yellow, yellow] (5,2.6) --  (5,4) ;
 \draw[spath/save=lime, lime] (2,2)  -- (2,5) ;

 \tikzset{
  spath/split at intersections={lime}{red},
  spath/split at intersections={lime}{blue},
  spath/split at intersections={blue}{orange},
  spath/split at intersections={orange}{yellow},
  spath/split at intersections={yellow}{green},
  spath/split at intersections={green}{red},
  spath/get components of={lime}\limecpts,
  spath/get components of={red}\redcpts,
  spath/get components of={blue}\bluecpts,
  spath/get components of={orange}\orangecpts,
  spath/get components of={yellow}\yellowcpts,
  spath/get components of={green}\greencpts,
  }

  \fill[
  orange,
  spath/restore=\getComponentOf\orangecpts{2}
  ]
  [
  spath/append=\getComponentOf\yellowcpts{2},
  spath/append=\getComponentOf\greencpts{2},
  spath/append reverse=\getComponentOf\redcpts{2},
  spath/append reverse =\getComponentOf\limecpts{2},
  spath/append=\getComponentOf\bluecpts{2},
  ]
  ;

  %% Useful for figuring out which components to use and what direction they go in
  \foreach \pth/\cpts in {lime/\limecpts,red/\redcpts,blue/\bluecpts,orange/\orangecpts,yellow/\yellowcpts,green/\greencpts}
  {
  \expandafter\let\expandafter\cpts\cpts
  \foreach[count=\k] \cpt in \cpts
  {
  \node[font=\tiny] at (spath cs:{\cpt} .5) {\pth-\k};
  \node[transform shape, spath/transform to=\cpt{.8}, font=\tiny] {>};
  } 
  }


  \filldraw[green] (3.2,3) to[closed,curve through={(3.3,4)}] (3.5,3) ;


\end{tikzpicture}

\end{document}

spath3 example

No attempt to create a shaded area with scope environments

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}

\usetikzlibrary{spath3,intersections,hobby}

\ExplSyntaxOn

\cs_set_eq:NN \getComponentOf \clist_item:Nn

\ExplSyntaxOff

\tikzset{ % from texexchange: transform defined coordinates in TikZ c/.style={every coordinate/.try} }

\begin{document}

\begin{tikzpicture}[thick, scale = 10]

\draw[yellow, name path=yellow]  (2,0)  -- (0,-5)  ;
\draw[lime,name path=lime] (-1,-1) -- (-3,-5) ;

\begin{scope}[every coordinate/.style={shift={(-3,-4)}, rotate={(140)}}]
\draw[red, name path=red]  ([c]1,2) -- ([c]0,-4) ;
\draw[orange,name path=orange] ([c]-1,2)  -- ([c]-3,-4) ;
\end{scope}

\begin{scope}[every coordinate/.style={shift={(-1,-4)}, rotate={(240)}}]
\draw[blue, name path=blue]  ([c]2,2)  -- ([c]0,-2) ;
\draw[green,name path=green] ([c]-1,2) -- ([c]-3,-2) ;
\end{scope}

    \filldraw[green] (-1,-3) to[closed,curve through={(-0.5,-2.5)}] (-0.2,-3) ;


\end{tikzpicture}

\end{document}

scope example

Attempt to create a shaded area with scope environments


\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}

\usetikzlibrary{spath3,intersections,hobby}

\ExplSyntaxOn

\cs_set_eq:NN \getComponentOf \clist_item:Nn

\ExplSyntaxOff

\tikzset{ % from texexchange: transform defined coordinates in TikZ c/.style={every coordinate/.try} }

\begin{document}

\begin{tikzpicture}[thick, scale = 10]

\draw[yellow, spath/save=yellow]  (2,0)  -- (0,-5)  ;
\draw[lime,spath/save=lime] (-1,-1) -- (-3,-5) ;

\begin{scope}[every coordinate/.style={shift={(-3,-4)}, rotate={(140)}}]
\draw[red, spath/save=red]  ([c]1,2) -- ([c]0,-4) ;
\draw[orange,spath/save=orange] ([c]-1,2)  -- ([c]-3,-4) ;
\end{scope}

\begin{scope}[every coordinate/.style={shift={(-1,-4)}, rotate={(240)}}]
\draw[blue, spath/save=blue]  ([c]2,2)  -- [c]0,-2) ;
\draw[green,spath/save=green] ([c]-1,2) -- ([c]-3,-2) ;
\end{scope}


\tikzset{ spath/split at intersections={lime}{red}, spath/split at intersections={lime}{blue}, spath/split at intersections={blue}{orange}, spath/split at intersections={orange}{yellow}, spath/split at intersections={yellow}{green}, spath/split at intersections={green}{red}, spath/get components of={lime}\limecpts, spath/get components of={red}\redcpts, spath/get components of={blue}\bluecpts, spath/get components of={orange}\orangecpts, spath/get components of={yellow}\yellowcpts, spath/get components of={green}\greencpts }

  \fill[
    orange,
    spath/restore=\getComponentOf\orangecpts{2}
  ]
  [
    spath/append=\getComponentOf\yellowcpts{2},
    spath/append=\getComponentOf\greencpts{2},
    spath/append reverse=\getComponentOf\redcpts{2},
    spath/append reverse =\getComponentOf\limecpts{2},
    spath/append=\getComponentOf\bluecpts{2}
  ]
  ;



  %% Useful for figuring out which components to use and what direction they go in
\foreach \pth/\cpts in {lime/\limecpts,red/\redcpts,blue/\bluecpts,orange/\orangecpts,yellow/\yellowcpts,green/\greencpts}
{
  \expandafter\let\expandafter\cpts\cpts
  \foreach[count=\k] \cpt in \cpts
  {
    \node[font=\tiny] at (spath cs:{\cpt} .5) {\pth-\k};
    \node[transform shape, spath/transform to=\cpt{.8}, font=\tiny] {>};
  }
}


\filldraw[green] (-1,-3) to[closed,curve through={(-0.5,-2.5)}] (-0.2,-3) ;

\end{tikzpicture}

\end{document}

This fails to compilate.

Log output

This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.7.7)  9 JUL 2022 11:57
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**document
(./document.tex
LaTeX2e <2022-06-01> patch level 5
L3 programming layer <2022-07-04>
(/usr/local/texlive/2022/texmf-dist/tex/latex/standalone/standalone.cls
Document Class: standalone 2018/03/26 v1.3a Class to compile TeX sub-files stan
dalone
(/usr/local/texlive/2022/texmf-dist/tex/latex/tools/shellesc.sty
Package: shellesc 2019/11/08 v1.0c unified shell escape interface for LaTeX
Package shellesc Info: Restricted shell escape enabled on input line 77.
)
(/usr/local/texlive/2022/texmf-dist/tex/generic/iftex/ifluatex.sty
Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.

(/usr/local/texlive/2022/texmf-dist/tex/generic/iftex/iftex.sty Package: iftex 2022/02/03 v1.0f TeX engine tests )) (/usr/local/texlive/2022/texmf-dist/tex/latex/xkeyval/xkeyval.sty Package: xkeyval 2022/06/16 v2.9 package option processing (HA)

(/usr/local/texlive/2022/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/local/texlive/2022/texmf-dist/tex/generic/xkeyval/xkvutils.tex \XKV@toks=\toks16 \XKV@tempa@toks=\toks17

(/usr/local/texlive/2022/texmf-dist/tex/generic/xkeyval/keyval.tex)) \XKV@depth=\count185 File: xkeyval.tex 2014/12/03 v2.7a key=value parser (HA) )) \sa@internal=\count186 \c@sapage=\count187

(/usr/local/texlive/2022/texmf-dist/tex/latex/standalone/standalone.cfg File: standalone.cfg 2018/03/26 v1.3a Default configuration file for 'standalon e' class ) (/usr/local/texlive/2022/texmf-dist/tex/latex/base/article.cls Document Class: article 2021/10/04 v1.4n Standard LaTeX document class (/usr/local/texlive/2022/texmf-dist/tex/latex/base/size10.clo File: size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option) )

[Some omissions due to space limit.]

(/usr/local/texlive/2022/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv e ))

Package pgfplots Warning: running in backwards compatibility mode (unsuitable t ick labels; missing features). Consider writing \pgfplotsset{compat=1.18} into your preamble. on input line 19.

! Missing number, treated as zero. <to be read again> __dim_eval_end: l.50 }

? ! Emergency stop. <to be read again> __dim_eval_end: l.50 }

End of file on the terminal!

Here is how much of TeX's memory you used: 24193 strings out of 478024 648019 string characters out of 5838710 1020163 words of memory out of 5000000 42291 multiletter control sequences out of 15000+600000 469259 words of font info for 28 fonts, out of 8000000 for 9000 1141 hyphenation exceptions out of 8191 99i,2n,108p,717b,609s stack positions out of 10000i,1000n,20000p,200000b,200000s ! ==> Fatal error occurred, no output PDF file produced!

! Emergency stop. <to be read again> __dim_eval_end: l.50 }

! ==> Fatal error occurred, no output PDF file produced! Transcript written on document.log.

Timeout/Error status: 1 [pdflatex][document]

17757970
  • 323
  • 1
  • 8
  • 1
    Scopes create TeX groups so you need to get your spath definitions out of those groups to use them in your intersections. Simplest way is to use the global version of the save command, which - if I remember right - is spath/save global – Andrew Stacey Jul 09 '22 at 18:27
  • Thank you once again! That was the solution. Your knowledge is really impressive. – 17757970 Jul 09 '22 at 18:41
  • Well, I probably do know more than most about the spath3 package ... – Andrew Stacey Jul 09 '22 at 23:06
  • PS if that worked and has fixed it, you should consider posting an answer to your question with the working code. – Andrew Stacey Jul 09 '22 at 23:07
  • That is certainly an understatement, not only as package creator. :-) I meant in general. Thank you once again! – 17757970 Jul 09 '22 at 23:39

1 Answers1

1

All thanks to the modest Andrew!

(I have just realized that I twisted the code snippet in the original post, as I had too many versions of it. Therefore the above code will not work without correcting the direction of the paths. Sorry.)

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}

\usetikzlibrary{spath3,intersections,hobby}

\ExplSyntaxOn

\cs_set_eq:NN \getComponentOf \clist_item:Nn

\ExplSyntaxOff

\tikzset{ % from texexchange: transform defined coordinates in TikZ c/.style={every coordinate/.try} }

\begin{document}

\begin{tikzpicture}[very thick, every node/.style={scale=10}, scale=13]

\draw[yellow, spath/save global=yellow]  (2,0)  -- (0,-5)  ;
\draw[lime,spath/save global=lime] (-1,-1) -- (-3,-5) ;

\begin{scope}[every coordinate/.style={shift={(-3,-4)}, rotate={(140)}}]
\draw[red, spath/save global=red]  ([c]1,2) -- ([c]0,-4) ;
\draw[orange,spath/save global=orange] ([c]-1,2)  -- ([c]-3,-4) ;
\end{scope}

\begin{scope}[every coordinate/.style={shift={(-1,-4)}, rotate={(240)}}]
\draw[blue, spath/save global=blue]  ([c]2,2)  -- ([c]0,-2) ;
\draw[green,spath/save global=green] ([c]-1,2) -- ([c]-3,-2) ;
\end{scope}


\tikzset{ spath/split at intersections={lime}{red}, spath/split at intersections={lime}{blue}, spath/split at intersections={blue}{orange}, spath/split at intersections={orange}{yellow}, spath/split at intersections={yellow}{green}, spath/split at intersections={green}{red}, spath/get components of={lime}\limecpts, spath/get components of={red}\redcpts, spath/get components of={blue}\bluecpts, spath/get components of={orange}\orangecpts, spath/get components of={yellow}\yellowcpts, spath/get components of={green}\greencpts }

  \fill[
    orange,
    spath/restore=\getComponentOf\orangecpts{2}
  ]
  [
    spath/append reverse=\getComponentOf\yellowcpts{2},
    spath/append=\getComponentOf\greencpts{2},
    spath/append reverse=\getComponentOf\redcpts{2},
    spath/append =\getComponentOf\limecpts{2},
    spath/append reverse=\getComponentOf\bluecpts{2}
  ]
  ;




\filldraw[green] (-1,-3) to[closed,curve through={(-0.5,-2.5)}] (-0.2,-3) ;

\end{tikzpicture}

\end{document}

enter image description here

17757970
  • 323
  • 1
  • 8