我怎样才能删除图片中不必要的部分并使两部分彼此靠近?

我怎样才能删除图片中不必要的部分并使两部分彼此靠近?

我的图形很长,中间的某些部分不需要,我希望两个部分彼此靠近(如图所示)。如何在 tikz 中实现? 在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
‎\usetikzlibrary{arrows,calc}‎
‎\RequirePackage{tikzpagenodes}‎
‎\usepackage{xparse}‎‎
‎\NewDocumentCommand\DrawArrows{O{0.5}mmO{-latex}mm}{‎
‎\def\Step{#1}‎
‎\pgfmathsetmacro{\Second}{#5+\Step}‎
‎\foreach \Value [count=\xi] in {#5,\Second,...,#6}‎
  {
  ‎\path[overlay,name path=line\xi]‎ 
    ‎(\Value,100)‎ -- ‎(\Value,-100);‎
  ‎\path[name intersections={of=#2 and line\xi,by={1\xi}}];‎
  ‎\path[name intersections={of=#3 and line\xi,by={2\xi}}];‎
  ‎\ifdim#5pt<\Value pt\relax‎
    ‎\ifdim\Value pt<#6pt\relax‎
    ‎\draw[#4]‎
      ‎(1\xi)‎ -- ‎(2\xi);‎ 
  ‎\fi\fi‎
  }
}
‎\tikzset{%‎
    ‎Cote node/.style={%‎
        ‎midway‎,
        ‎sloped‎,
        ‎fill=white‎,
        ‎inner sep=1.5pt‎,
        ‎outer sep=2pt‎
    ‎}‎,
    ‎Cote arrow/.style={%‎
        ‎<->‎,
        ‎>=latex‎,
        ‎very thin‎
    }
}
‎\makeatletter‎
‎\NewDocumentCommand{\Cote}{%‎
    ‎s       % cotation avec les flèches à l'extérieur‎
    ‎D<>{1.5pt} % offset des traits‎
    ‎O{.75cm}    % offset de cotation‎
    ‎m       % premier point‎
    ‎m       % second point‎
    ‎m       % étiquette‎
    ‎D<>{o}  % () coordonnées‎ -‎> angle‎
            % ‎h‎ -‎> horizontal‎,
            % ‎v‎ -‎> vertical‎
            % ‎o or what ever‎ -‎> oblique‎
    ‎O{}     % parametre du tikzset‎
    }{%
    ‎{\tikzset{#8}‎
    ‎\coordinate (@1) at #4 ;‎
    ‎\coordinate (@2) at #5 ;‎
‎\if #7v % Cotation verticale‎
    ‎\coordinate (@0) at ($($#4!.5!#5$)‎ + ‎(#3,0)$) ;‎ 
    ‎\coordinate (@4) at (@0|-@1) ;‎
    ‎\coordinate (@5) at (@0|-@2) ;‎
‎\else‎
‎\if #7h % Cotation horizontale‎
    ‎\coordinate (@0) at ($($#4!.5!#5$)‎ + ‎(0,#3)$) ;‎ 
    ‎\coordinate (@4) at (@0-|@1) ;‎
    ‎\coordinate (@5) at (@0-|@2) ;‎
‎\else % cotation encoche‎
‎\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@‎
    ‎\coordinate (@5) at ($#7!#3!#5$) ;‎
    ‎\coordinate (@4) at ($#7!#3!#4$) ;‎
‎\else % cotation oblique‎    
    ‎\coordinate (@5) at ($#5!#3!90:#4$) ;‎
    ‎\coordinate (@4) at ($#4!#3!-90:#5$) ;‎
‎\fi\fi\fi‎

‎\draw[very thin,shorten >= #2,shorten <=‎ -‎2*#2] (@4)‎ -- ‎#4 ;‎
‎\draw[very thin,shorten >= #2,shorten <=‎ -‎2*#2] (@5)‎ -- ‎#5 ;‎

‎\IfBooleanTF #1 {% avec étoile‎
‎\draw[Cote arrow,-] (@4)‎ -- ‎(@5)‎
    ‎node[Cote node] {#6\strut};‎
‎\draw[Cote arrow,<-] (@4)‎ -- ‎($(@4)!-6pt!(@5)$) ;‎   
‎\draw[Cote arrow,<-] (@5)‎ -- ‎($(@5)!-6pt!(@4)$) ;‎   
}{% ‎sans étoile‎
‎\ifnum\pdfstrcmp{\unexpanded\expandafter{\@car#7\@nil}}{(}=\z@‎
    ‎\draw[Cote arrow] (@5) to[bend right]‎
        ‎node[Cote node] {#6\strut} (@4) ;‎
‎\else‎
‎\draw[Cote arrow] (@4)‎ -- ‎(@5)‎
    ‎node[Cote node] {#6\strut};‎
‎\fi‎
}}
}
\begin{document}
\begin{tikzpicture}
   ‎\coordinate (O) at (0,0);‎‎
        \Cote{(2,-.5)}{(2,.5)}{‎$‎b(x)‎$‎}[ Cote node/.append style={right,rotate=-90}];
\Cote[1cm]{(0,0)}{(4,0)}{‎$‎L‎$‎}  ;
 ‎\fill[blue!30,opacity=0.65] (0,0.15)..controls(2,.55).. (4,0.4)--(4,-0.4) ..controls(2,-.55)..  (0,-0.15)‎ -- ‎cycle;‎‎‎
  ‎\draw[thick] (0,0.15)..controls(2,.55).. (4,0.4)--(4,-0.4) ..controls(2,-.55)..  (0,-0.15)‎ -- ‎cycle;‎‎‎
         ‎\draw[->] (O)‎ -- +‎+(0,1.1) node[right] {$y$};‎
        ‎\draw[->] (O)‎ -- +‎+(1,0) node[above] {$x$};‎‎
  ‎\end{tikzpicture}‎
\end{document}

答案1

最简单的方法是在原始图像上填充白色。

为了使两部分更靠近,我使用裁剪矩形绘制了两次。左侧部分在第一个范围内裁剪,右侧部分在第二个范围内裁剪。

请注意,如果将它们移得太近,白色填充可能会与部分图像重叠。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}
  \clip (-.2,-1.2) rectangle (1.6,1.2);% clip left part
  \path[fill=blue!30,opacity=0.65,draw=black,thick] (0,0.15) ..controls(2,.55).. (4,0.4)--
    (4,-0.4) ..controls(2,-.55).. (0,-0.15) -- cycle;
  \fill[white] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1)--
    (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1) -- cycle;
  \draw[black,very thick] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1);
  \draw[black,very thick] (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1);
  \coordinate (O) at (0,0);
  \draw[->] (O) -- ++(0,1.1) node[right] {$y$};
  \draw[->] (O) -- ++(1,0) node[above] {$x$};
\end{scope}
\begin{scope}[xshift=-1.5cm]
  \clip (3.2,-1.2) rectangle (4.2,1.2);% clip right part
  \path[fill=blue!30,opacity=0.65,draw=black,thick] (0,0.15) ..controls(2,.55).. (4,0.4)--
    (4,-0.4) ..controls(2,-.55).. (0,-0.15) -- cycle;
  \fill[white] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1)--
    (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1) -- cycle;
  \draw[black,very thick] (1.5,1) ..controls(1.6,.6) and (1.2,-.5).. (1.5,-1);
  \draw[black,very thick] (3.5,-1) ..controls(3.2,-.5) and (3.6,.6).. (3.5,1);
  \coordinate (O) at (0,0);
  \draw[->] (O) -- ++(0,1.1) node[right] {$y$};
  \draw[->] (O) -- ++(1,0) node[above] {$x$};
\end{scope}
\end{tikzpicture}
\end{document}

剪切和移位

相关内容