这是 MWE

这是 MWE

我的目标是拥有一个具有透明背景的标签,但任何穿过标签假设框的连接曲线都必须被隐藏。

不透明标签

\ncput*生成如下不透明标签。因此它不符合我的目标。

\documentclass[pstricks,multi]{standalone}
\usepackage{pst-eucl}

\begin{document}
\begin{pspicture}[showgrid=false](4,4)
    \pstGeonode[PosAngle={90}]
        (1,1){A}
        (3,3){B}
    \ncarc[arcangle=-30,linestyle=dashed,linecolor=gray]{A}{B}
  \ncput*[nrot=:0]{$2\sqrt2$}   
\end{pspicture}

\end{document}

透明标签

以下是我尝试模仿上述代码但标签背景为透明的尝试。但是,我没能模仿出连接曲线。

\documentclass[pstricks,multi]{standalone}
\usepackage{pst-eucl}

\begin{document}

\begin{pspicture}[showgrid=false](4,4)
    \pstGeonode[PosAngle={90}]
        (1,1){A}
        (3,3){B}
    \ncarc[arcangle=-30,linestyle=none]{A}{B}
  \ncput[nrot=:0]{\psDefBoxNodes{obj}{$2\sqrt2$}}
    \pcarc[arcangle=-30,linestyle=dashed,linecolor=gray](A)([nodesep=3pt]{A}obj:Cl)
  \pcarc[arcangle=-30,linestyle=dashed,linecolor=gray]([nodesep=3pt]{B}obj:Cr)(B)
\end{pspicture}

\end{document}

如何解决这个问题?

答案1

我定义了一个宏,用于连接两个点的简单二次贝塞尔曲线。但是,我还添加了两个参数,以便您指定要绘制的贝塞尔曲线部分的起点和终点。

命令的参数是

 \mybeziercurve[options]{<t-start>}{<t-end>}{<n-start>}{<n-control>}{<n-end>}

在哪里

t-start    is a value between 0 and 1
t-end      is a value between 0 and 1 (ideally larger than t-start)
n-start    is the first node to be connected
n-control  is a node to control the effect of the bezier curve
n-end      is the second node to be connected

还有一个命令可以沿贝塞尔曲线放置一个点

\myputnodeoncurve{<pos>}{<node-start>}{<control-node>}{<node-end>}{<new-node>}

在哪里

pos  should be a number between 0 and 1

other parameters are as for \mybeziercurve

请注意此实现要求您使用,pst-eucl因为我使用的pst-eucl后记词典

这是 MWE

\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-plot}
\usepackage{pst-eucl}

\makeatletter
\newcommand{\@my@bezier@curve}[4]
    {%
            tx@EcldDict begin
            %% x coordinate
            1 #1 sub
            1 #1 sub
                    /N@#2 GetNode 0 mul add     mul
            #1
                    /N@#3 GetNode 0 mul add     mul add mul
            %--
              #1 
            1 #1 sub
                    /N@#3 GetNode 0 mul add     mul
              #1
                    /N@#4 GetNode 0 mul add     mul add mul add
            \pst@number\psxunit div
            %% y coordinate
            1 #1 sub
            1 #1 sub
                    /N@#2 GetNode exch 0 mul add     mul
            #1
                    /N@#3 GetNode exch 0 mul add     mul add mul
            %--
              #1 
            1 #1 sub
                    /N@#3 GetNode exch 0 mul add     mul
              #1
                    /N@#4 GetNode exch 0 mul add     mul add mul add
            \pst@number\psyunit div
            end
    }

\newcommand{\mybeziercurve}[6][]
    {%
        \def\@ParamStart{#2}%
        \def\@ParamEnd{#3}%
        \parametricplot[plotstyle=line,plotpoints=100,#1]
        {\@ParamStart}{\@ParamEnd}{ \@my@bezier@curve{t}{#4}{#5}{#6} }        
    }
%% a macro to place a node on the curve for labeling purposes
\newcommand{\myputnodeoncurve}[5]
    {%
        \pnode( !\@my@bezier@curve{#1}{#2}{#3}{#4} ){#5}%
    }
\makeatother
\pagestyle{empty}
\begin{document}

\begin{pspicture}[showgrid=false](0,0)(4,4)
    \pstGeonode[PosAngle={-135,45,-45},
                PointName={default,default,none},
                PointSymbol={default,default,none}]
        (2,1){A}
        (3,3){B}
        (3,1){C}

    \pstRotation[RotAngle=130,PointName=none,PointSymbol=none]{A}{C}[D]
    \pstTranslation[DistCoef=-1.5,PointName=none,PointSymbol=none]{C}{D}{C}[D]

    \mybeziercurve[linecolor=black,linewidth=0.4pt,linestyle=dashed]{0}{0.35}{A}{D}{B}
    \mybeziercurve[linecolor=black,linewidth=0.4pt,linestyle=dashed]{0.65}{1}{A}{D}{B}

    \myputnodeoncurve{0.5}{A}{D}{B}{E}
    \rput(E){$\sqrt{2}$}

\end{pspicture}
\end{document}

在此处输入图片描述

看起来更像你想要的东西

\begin{pspicture}[showgrid=false](0,0)(4,4)
    \pstGeonode[PosAngle={-135,45,-45},
                PointName={default,default,none},
                PointSymbol={default,default,none}]
        (2,1){A}
        (5,5){B}
        (5,1){C}
\mybeziercurve[linecolor=black,linewidth=0.4pt,linestyle=dashed]{0}{0.40}{A}{C}{B}
\mybeziercurve[linecolor=black,linewidth=0.4pt,linestyle=dashed]{0.60}{1}{A}{C}{B}

\myputnodeoncurve{0.5}{A}{C}{B}{E}
\rput(E){$\sqrt{2}$}
\end{pspicture}

您选择的位置控制点可以让你更好地塑造曲线。

在此处输入图片描述

您可以将以下内容添加到您的序言中:

%% command to get angle 
\newcommand{\mygetangle}[2]
    {   !
        tx@EcldDict begin
        /N@#2 GetNode 0 mul add
        /N@#1 GetNode 0 mul add sub 
        /N@#2 GetNode exch 0 mul add
        /N@#1 GetNode exch 0 mul add sub 
        exch
        atan
        end
     } 

然后你可以使用

\begin{pspicture}[showgrid=false](0,0)(4,4)
   \pstGeonode[PosAngle={-135,45,-45},
               PointName={default,default,none},
               PointSymbol={default,default,none}]
       (2,1){A}
       (5,5){B}
       (5,1){C}


   \mybeziercurve[linecolor=black,linewidth=0.4pt,linestyle=dashed]{0}{0.40}{A}{C}{B}
   \mybeziercurve[linecolor=black,linewidth=0.4pt,linestyle=dashed]{0.60}{1}{A}{C}{B}

   %% Setting points to get slope of omitted section
   \myputnodeoncurve{0.40}{A}{C}{B}{E1}
   \myputnodeoncurve{0.50}{A}{C}{B}{E}
   \myputnodeoncurve{0.60}{A}{C}{B}{E2}
   \rput{\mygetangle{E1}{E2}}(E){$\sqrt{2}$}

\结束{pspicture}

在此处输入图片描述

相关内容