我尝试在六条路径内创建一个阴影区域。我尝试遵循
这个答案该包spath3
被使用过的地方。
正如您在第一张图片中看到的那样,当我知道路径的明确坐标时,它的工作方式与预期一致。然而,我现实生活中的问题包括范围环境中的旋转和移位,这在第二和第三个示例中显示,并以某种方式阻碍了该方法的纳入。不幸的是,我只能为范围环境示例创建一个类似的,而不是相同的图形。
在使用范围环境时,是否有任何解决方案可以创建阴影区域?我不一定受限于包spath3
。非常感谢。
阴影 - 具有精确坐标的 spath3
\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}
不尝试使用范围环境创建阴影区域
\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}
尝试使用范围环境创建阴影区域
\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 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]
答案1
这一切都要感谢谦虚的安德鲁!
(我刚刚意识到我扭曲了原始帖子中的代码片段,因为我有太多版本。因此,如果不纠正路径的方向,上述代码将无法工作。抱歉。)
\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}