TikZ:如何在填充区域周围的曲线中放置间隙

TikZ:如何在填充区域周围的曲线中放置间隙

下图是对以下问题的修改:手绘草图,导入 TikZ

图片中的标签 $K$ 和 $U_y$ 分别表示:具有粗实线边界的蓝色填充区域;以及最右上角的区域,具有虚线边界,部分为橙色填充,但与区域重叠. 每个标签都被边界的部分遮挡:标签 $K$ 被 $U_y$ 边界的虚线下部所遮挡;标签 $U_y$ 被区域

问题:我怎样才能打破这两个界限,以便标签更容易被看到?

更具体地说,是否有一些好的方法可以避免在边界上定位合适的点来停止和重新启动边界曲线时进行大量的反复试验?

笔记:最终图片将使用灰色阴影,而不是红色、蓝色和橙色,正如现在注释掉的带有 3 个\definecolor命令的代码块所指定的那样。我保留所示的颜色,以便更清楚地指示哪个区域是哪个区域。)

\documentclass[tikz,border=0pt]{standalone}    
% Based upon answer by @marmot 2018/06/10
% https://tex.stackexchange.com/questions/435746/sketching-free-hand-importing-into-tikz

\usetikzlibrary{calc,intersections,arrows.meta,backgrounds}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

%\definecolor{red}{gray}{0.15} % medium gray for region V
%\definecolor{blue}{gray}{0.2} % dark gray for region K
%\definecolor{orange}{gray}{0.6}% light shading for left & right sides    

\begin{document}

\begin{tikzpicture}[long dash/.style={dash pattern=on 4pt off 2pt},
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 3pt,  % size of the circle diameter 
x=0.44cm,y=0.44cm % scale units for overall correct size
] 

% Left-hand regions
\draw[thick,long dash,name path=left,fill=orange!30] plot[smooth cycle] coordinates 
    {(0.3,-2) (-1,-3) (-8,-1.2) (-8.8,-0.2) (-7,0.6) (-1,-0.6)};
\draw[thick,long dash,name path=left bottom] plot[smooth cycle] coordinates 
    {(-8,-2.8) (-9,-2.5) (-8.5,-1) (-7,0) (-6,1.7) (-5,1.7) (-4,-0) (-5.5,-2)};
\draw[thick,long dash,name path=left top] plot[smooth cycle] coordinates 
    {(-7.2,-1) (-7.8,1) (-6.7,2) (-5.5,1) (-5,0) (-5.4,-1) (-6,-1.2)};
\path [%draw,blue,ultra thick,
    name path=left arc,
    intersection segments={
        of=left top and left,
        sequence={A1--B1}
    }];
\path [%draw,red,ultra thick,
    fill=red!30,
    name path=left blob,
    intersection segments={
        of=left bottom and left arc,
        sequence={A1--B0}
    }];
% Right-hand regions
\path[fill=orange!30] plot[smooth cycle] coordinates % region U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\path[fill=blue!30] plot[smooth cycle] coordinates % region K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
(6,-2.3) (4,-2.3) (2,-2)};
\draw[thick,long dash,name path=right top] plot[smooth cycle] coordinates % boundary of U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\draw[thick,name path=right] plot[smooth cycle] coordinates % boundary of K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
    (6,-2.3) (4,-2.3) (2,-2)};
% boundary of unnamed region to lower-left of point y:
\draw[thick,long dash,name path=middle] plot[smooth cycle] coordinates 
    {(0,-3.4) (-1,-2) (-1,-0.5) (-1.5,0.4) (-1,1.6) (0,1.9) (2.1,1) (3,-1) (2.5,-3) (1,-3.7)};
% boundary of unnamed region to lower-rightof point y:
\draw[thick,long dash,name path=right bottom] plot[smooth cycle] coordinates 
    {(1,-3) (0.6,-2) (1.2,0) (3,0.8) (6,0.8) (8.5,1) (10,0) (9,-3) (7,-3.7) (5,-3.6) (2,-3.6)};
\path[name path=circle] (5.2,1.5) arc(-30:190:4mm);
\path [%draw,red,ultra thick,
    name path=aux1,
    intersection segments={
        of=circle and right,
        sequence={B1}
    }];
\path [draw,ultra thick,
    name path=aux2,
    intersection segments={
        of=circle and aux1,
        sequence={B0}
    }];

% Distinguished points & their labels
\node[dot] at (-6.5,-0.425) {};
\node at (-6.95,-0.675) {$x$};
\node[dot] at (3.3,1.5) {};
\node at (2.85,1.25) {$y$}; 

% Region labels
\node at (-5.625,-0.025) {$V$};
\node at (-2.5,-1.5){$V_y$};  
\node[] at (3.7,0){$K$}; 
\node[] at (4.8,1.6) {$U_y$};

\end{tikzpicture}    
\end{document}

区域——需要打破两个界限,才能让标签更明显。

答案1

更新:适用于所有路径(无论是否为虚线)的方法:使用reverse clip方法。首先绘制文本节点,然后反向剪切其周围的一小块区域,然后绘制所有想要有间隙的轮廓。

\documentclass[tikz,border=0pt]{standalone}    
% Based upon answer by @marmot 2018/06/10
% https://tex.stackexchange.com/questions/435746/sketching-free-hand-importing-into-tikz

\usetikzlibrary{calc,intersections,arrows.meta,backgrounds,decorations.markings}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
% from https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  (current page.north east)}
}}


%\definecolor{red}{gray}{0.15} % medium gray for region V
%\definecolor{blue}{gray}{0.2} % dark gray for region K
%\definecolor{orange}{gray}{0.6}% light shading for left & right sides    

\begin{document}

\begin{tikzpicture}[long dash/.style={dash pattern=on 4pt off 2pt},
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 3pt,  % size of the circle diameter 
x=0.44cm,y=0.44cm % scale units for overall correct size
] 

% Left-hand regions
\draw[thick,long dash,name path=left,fill=orange!30] plot[smooth cycle] coordinates 
    {(0.3,-2) (-1,-3) (-8,-1.2) (-8.8,-0.2) (-7,0.6) (-1,-0.6)};
\draw[thick,long dash,name path=left bottom] plot[smooth cycle] coordinates 
    {(-8,-2.8) (-9,-2.5) (-8.5,-1) (-7,0) (-6,1.7) (-5,1.7) (-4,-0) (-5.5,-2)};
\draw[thick,long dash,name path=left top] plot[smooth cycle] coordinates 
    {(-7.2,-1) (-7.8,1) (-6.7,2) (-5.5,1) (-5,0) (-5.4,-1) (-6,-1.2)};
\path [%draw,blue,ultra thick,
    name path=left arc,
    intersection segments={
        of=left top and left,
        sequence={A1--B1}
    }];
\path [%draw,red,ultra thick,
    fill=red!30,
    name path=left blob,
    intersection segments={
        of=left bottom and left arc,
        sequence={A1--B0}
    }];
% Right-hand regions
\path[fill=orange!30] plot[smooth cycle] coordinates % region U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\path[fill=blue!30] plot[smooth cycle] coordinates % region K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
(6,-2.3) (4,-2.3) (2,-2)};
\begin{scope}
\node[] at (3.7,0)[fill=blue!30]{$K$};
\clip[overlay] (3.7,0) circle (8pt) [reverseclip];
\draw[thick,long dash,name path=right top] plot[smooth cycle] coordinates % boundary of U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
% \end{scope}
% \begin{scope} 
\node at (4.8,1.6) {$U_y$};
\clip[overlay] (4.8,1.6) circle (10pt) [reverseclip];
\draw[thick,name path=right] plot[smooth cycle] coordinates % boundary of K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
    (6,-2.3) (4,-2.3) (2,-2)};
\end{scope} 
% boundary of unnamed region to lower-left of point y:
\draw[thick,long dash,name path=middle] plot[smooth cycle] coordinates 
    {(0,-3.4) (-1,-2) (-1,-0.5) (-1.5,0.4) (-1,1.6) (0,1.9) (2.1,1) (3,-1) (2.5,-3) (1,-3.7)};
% boundary of unnamed region to lower-rightof point y:
\draw[thick,long dash,name path=right bottom] plot[smooth cycle] coordinates 
    {(1,-3) (0.6,-2) (1.2,0) (3,0.8) (6,0.8) (8.5,1) (10,0) (9,-3) (7,-3.7) (5,-3.6) (2,-3.6)};
\path[name path=circle] (5.2,1.5) arc(-30:190:4mm);
\path [%draw,red,ultra thick,
    name path=aux1,
    intersection segments={
        of=circle and right,
        sequence={B1}
    }];
\path [draw,ultra thick,
    name path=aux2,
    intersection segments={
        of=circle and aux1,
        sequence={B0}
    }];

% Distinguished points & their labels
\node[dot] at (-6.5,-0.425) {};
\node at (-6.95,-0.675) {$x$};
\node[dot] at (3.3,1.5) {};
\node at (2.85,1.25) {$y$}; 

% Region labels
\node at (-5.625,-0.025) {$V$};
\node at (-2.5,-1.5){$V_y$};  
% Derek's comment

%

\end{tikzpicture}    
\end{document}

在此处输入图片描述

旧答案:这是一种适用于实线边界的简单方法。调整虚线图案的长度,以便在正确的位置留出间隙。当然,您可以通过将文本放置decorations.markings在间隙的中间来使其更优雅。但对于虚线,我建议使用我之前回答的方法。(如果您不喜欢该方法,则无需加载 pgfplots 及其库fillbetween编辑:我错了,你确实需要fillbetween包含该地区的东西x。我还实现了Derek 的精彩评论但很乐意将其删除。

\documentclass[tikz,border=0pt]{standalone}    
% Based upon answer by @marmot 2018/06/10
% https://tex.stackexchange.com/questions/435746/sketching-free-hand-importing-into-tikz

\usetikzlibrary{calc,intersections,arrows.meta,backgrounds,decorations.markings}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

%\definecolor{red}{gray}{0.15} % medium gray for region V
%\definecolor{blue}{gray}{0.2} % dark gray for region K
%\definecolor{orange}{gray}{0.6}% light shading for left & right sides    

\begin{document}

\begin{tikzpicture}[long dash/.style={dash pattern=on 4pt off 2pt},
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 3pt,  % size of the circle diameter 
x=0.44cm,y=0.44cm % scale units for overall correct size
] 

% Left-hand regions
\draw[thick,long dash,name path=left,fill=orange!30] plot[smooth cycle] coordinates 
    {(0.3,-2) (-1,-3) (-8,-1.2) (-8.8,-0.2) (-7,0.6) (-1,-0.6)};
\draw[thick,long dash,name path=left bottom] plot[smooth cycle] coordinates 
    {(-8,-2.8) (-9,-2.5) (-8.5,-1) (-7,0) (-6,1.7) (-5,1.7) (-4,-0) (-5.5,-2)};
\draw[thick,long dash,name path=left top] plot[smooth cycle] coordinates 
    {(-7.2,-1) (-7.8,1) (-6.7,2) (-5.5,1) (-5,0) (-5.4,-1) (-6,-1.2)};
\path [%draw,blue,ultra thick,
    name path=left arc,
    intersection segments={
        of=left top and left,
        sequence={A1--B1}
    }];
\path [%draw,red,ultra thick,
    fill=red!30,
    name path=left blob,
    intersection segments={
        of=left bottom and left arc,
        sequence={A1--B0}
    }];
% Right-hand regions
\path[fill=orange!30] plot[smooth cycle] coordinates % region U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\path[fill=blue!30] plot[smooth cycle] coordinates % region K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
(6,-2.3) (4,-2.3) (2,-2)};
\draw[thick,long dash,name path=right top] plot[smooth cycle] coordinates % boundary of U_{u}
    {(-1.3,2) (-0.7,3) (1,3.7) (5.2,3) (8,1.6) (8.4,1) (8,0.3) (6,0) (4,0) (2,0.3) (0,1)};
\draw[thick,name path=right,dash pattern=on 118pt off 16pt on 300pt,
postaction={decorate,decoration={markings,mark=at position 126pt with
{\node{$U_y$};}}}] plot[smooth cycle] coordinates % boundary of K
    {(0,-2) (-0.3,-1.5) (-0.2,0) (-0.3,1) (-1,2) (0,2.8) (3,2) (7,1) (7.3,-1)
    (6,-2.3) (4,-2.3) (2,-2)};
% boundary of unnamed region to lower-left of point y:
\draw[thick,long dash,name path=middle] plot[smooth cycle] coordinates 
    {(0,-3.4) (-1,-2) (-1,-0.5) (-1.5,0.4) (-1,1.6) (0,1.9) (2.1,1) (3,-1) (2.5,-3) (1,-3.7)};
% boundary of unnamed region to lower-rightof point y:
\draw[thick,long dash,name path=right bottom] plot[smooth cycle] coordinates 
    {(1,-3) (0.6,-2) (1.2,0) (3,0.8) (6,0.8) (8.5,1) (10,0) (9,-3) (7,-3.7) (5,-3.6) (2,-3.6)};
\path[name path=circle] (5.2,1.5) arc(-30:190:4mm);
\path [%draw,red,ultra thick,
    name path=aux1,
    intersection segments={
        of=circle and right,
        sequence={B1}
    }];
\path [draw,ultra thick,
    name path=aux2,
    intersection segments={
        of=circle and aux1,
        sequence={B0}
    }];

% Distinguished points & their labels
\node[dot] at (-6.5,-0.425) {};
\node at (-6.95,-0.675) {$x$};
\node[dot] at (3.3,1.5) {};
\node at (2.85,1.25) {$y$}; 

% Region labels
\node at (-5.625,-0.025) {$V$};
\node at (-2.5,-1.5){$V_y$};  
% Derek's comment
\node[] at (3.7,0)[fill=blue!30]{$K$};
%\node[] at (4.8,1.6) {$U_y$};

\end{tikzpicture}    
\end{document}

在此处输入图片描述

相关内容