在节点和边周围绘制动态圆圈

在节点和边周围绘制动态圆圈

如何添加如下图所示的红色圆圈,但带有虚线圆圈。

在此处输入图片描述

我希望它遵循路径结构。

到目前为止,这是我的代码:

\begin{forest}
[$root : s_0$
[$a: s_*$
[$d: s_*$]
[$d: s_*$
[$c: s_*$]
]
]
[$a: s_a$
[$b: s_b$
[$c: s_c$]
]
[$b: s_*$
[$d: s_*$]
[$c: s_*$
[$d: s_*$
[$d: s_*$]
]
]
]
]
]
\end{forest}

答案1

hobby软件包中有一些算法可以帮助你绘制这样的曲线。这是一个快速的建议,如果你花更多的时间调整一些东西,你可以让你的曲线更漂亮。

\documentclass[tikz]{standalone}
\usepackage{forest}
\usetikzlibrary{hobby}
\begin{document}
\begin{forest}
[$root : s_0$, name= s0
    [$a: s_*$
        [$d: s_*$]
        [$d: s_*$
            [$c: s_*$]
        ]
    ]
    [$a: s_a$, name= sa
        [$b: s_b$, name= sb
            [$c: s_c$, name= sc]
        ]
        [$b: s_*$
            [$d: s_*$]
            [$c: s_*$
                [$d: s_*$
                    [$d: s_*$]
                ]
            ]
        ]
    ]
]
\draw[dashed,red] (s0.west) to[closed,curve through={
    (s0.south)..(sb.north west)..(sc.south west)..
    (sc.south east)..([xshift=.2cm]sb.east)..
    (sa.east)..(s0.east)..([tension in=-2]s0.north)
}] (s0.west);
\end{forest}
\end{document}

在此处输入图片描述

答案2

像这样?

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{forest}


\begin{document}
\begin{forest}
[$root : s_0$, name= s0
[$a: s_*$
[$d: s_*$]
[$d: s_*$
[$c: s_*$]
]
]
[$a: s_a$, name= sa
[$b: s_b$, name= sb
[$c: s_c$, name= sc]
]
[$b: s_*$
[$d: s_*$]
[$c: s_*$
[$d: s_*$
[$d: s_*$]
]
]
]
]
]
\draw[dashed,red]
 (s0.20) .. controls ++([shift={(0:1.25)}]sa) and (sb.0) .. (sc.0)
 .. controls ([shift={(-90:1)}]sc) and ([shift={(-180:0.75)}]sc) .. (sb.180)
  .. controls ([shift={(160:2)}]s0) and (s0.90) .. cycle;
\end{forest}
\end{document}

在此处输入图片描述

相关内容