此代码
\begin{tikzpicture}
% Vertice con 5 archi
\node[circle, draw] (v) at (0,0) {V};
% Archi tratteggiati
\draw (v.45) -- ++(45:1);
\draw (v.90) -- ++(90:1);
\draw (v.135) -- ++(135:1);
\draw (v.180) -- ++(180:1);
\draw (v.225) -- ++(225:1);
\draw[dashed] (v.45) -- ++(45:2);
\draw[dashed] (v.90) -- ++(90:2);
\draw[dashed] (v.135) -- ++(135:2);
\draw[dashed] (v.180) -- ++(180:2);
\draw[dashed] (v.225) -- ++(225:2);
\end{tikzpicture}
绘制下面的图片
我想添加一条非直线路径,使用不同的颜色,从一条线进入并从另一条线退出,类似于下图所示的路径(由我手动修改):
我怎样才能获得这个结果?
答案1
耐心地使用 Luc Cholet 的Geogebra
文件https://www.geogebra.org/m/RwNHMPk9,我们可以创建贝塞尔曲线。
- 为了更容易在 Geogebra 中定位点 p1 和 p2,我们将
minimum width=1cm
包含 V 的节点设置为 - 在 Geogebra 中,我们通过在输入字段中输入来重新定义点 A 的坐标
A=(2.5; 45°)
- 我们可以使用 + 按钮一次添加一个控制点。
- 最后使用 tikz 按钮复制然后粘贴到 tex 文件中
代码
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Vertice con 5 archi
\node[circle, draw,minimum width=1cm] (v) at (0,0) {V};%<-- modif
% Archi tratteggiati
\draw (v.45) -- ++(45:1);
\draw (v.90) -- ++(90:1);
\draw (v.135) -- ++(135:1);
\draw (v.180) -- ++(180:1);
\draw (v.225) -- ++(225:1);
\draw[dashed] (v.45) -- ++(45:2)coordinate(p1);
\draw[dashed] (v.90) -- ++(90:2)coordinate(p2);
\draw[dashed] (v.135) -- ++(135:2);
\draw[dashed] (v.180) -- ++(180:2);
\draw[dashed] (v.225) -- ++(225:2);
%
\draw [green](p1)%<-- mdif after copy
% \draw (1.7677669529663689,1.7677669529663687)
.. controls (3.1070703811315195,3.165645932288138 ) and (1.7281913375772981,2.434840039204401 ) .. (1.5696202475685628,2.2693745539778947)
.. controls (1.4110491575598274,2.1039090687513884 ) and (1.2111116962444652,2.579622338777594 ) .. (1.5075706906086228,2.620988710084221)
.. controls (1.8040296849727804,2.6623550813908476 ) and (1.245583672333321,3.1242795609815115 ) .. (0.9767022588402476,2.5865167339953654)
.. controls (0.7078208453471744,2.0487539070092193 ) and (0.5,3.5 ) ..
% (0,2.5);
(p2);%<-- mdif after copy
\end{tikzpicture}
\end{document}
答案2
整合几个库……
arrows.meta
以及bending
可定制且灵活/可弯曲的箭头,decorations.markings
用于沿路径放置箭头,ext.arrows
从我的tikz-ext
包裹对于Centered Straight Barb
箭头,fpu
更多精确的veclen
函数会修复Dimension too large
一些贝塞尔曲线的错误,hobby
smooth
寻找通过坐标构造曲线的 plothandler的替代方案,以及math
允许简单的界面进行即时计算。
后者用于不是使用随机坐标但虚线的终点。
两者hobby
和smooth
绘图处理器允许定制底层算法来通过给定的点构建曲线。
默认输出如下所示。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{
arrows.meta, % customizable arrow tips
bending, % flexed and bended arrow tips
decorations.markings, % place arrow tips along any path
ext.arrows, % Centered Straight Barb
fpu, % more precise veclen function for decoration along curve
hobby, % nicer (?) curves through points
math} % on-the-fly calculations
\begin{document}
\begin{tikzpicture}[
thick, arrows={[round, scale=.5]},
> ={ Straight Barb[flex']}, % arrow tip for the end
>'/.tip={Centered Straight Barb[quick]}] % arrow tip for along the path
\pgfmathsetseed{699943}
\node[circle, draw] (v) at (0,0) {V};
\foreach[count=\i from 0] \ang in {45, 90, ..., 225}
\path (v.\ang) edge coordinate[at end](v'\i) (\ang:1)
(v'\i) edge[dash pattern=on 1.3333mm off 1mm]
coordinate[at end](v''\i) (\ang:2);
\draw[
cyan, <-, thin, /pgf/fpu/install only=veclen,
postaction=decorate,
decoration={
name=markings,
mark=between positions .125 and .875 step .125 with \arrowreversed{>'}
}
] plot[smooth, samples at={0, ..., 40}]
([evaluate={
coordinate \p; int \i;
if mod(\x,10) == 0 then {
\i = int(\x/10);
\p = (v''\i);
} else {
\p = ({45+\x/40*180+rand}:{2+rand*.2});
};}, shift={(\p)}]0pt,0pt);
\end{tikzpicture}
\begin{tikzpicture}[
thick, arrows={[round, scale=.5]},
> ={ Straight Barb[flex']}, % arrow tip for the end
>'/.tip={Centered Straight Barb[quick]}] % arrow tip for along the path
\pgfmathsetseed{699943}
\node[circle, draw] (v) at (0,0) {V};
\foreach[count=\i from 0] \ang in {45, 90, ..., 225}
\path (v.\ang) edge coordinate[at end](v'\i) (\ang:1)
(v'\i) edge[dash pattern=on 1.3333mm off 1mm]
coordinate[at end](v''\i) (\ang:2);
\draw[
cyan, <-, thin, /pgf/fpu/install only=veclen,
postaction=decorate,
decoration={
name=markings,
mark=between positions .125 and .875 step .125 with \arrowreversed{>'}
}
] plot[hobby, samples at={0, ..., 40}]
([evaluate={
coordinate \p; int \i;
if mod(\x,10) == 0 then {
\i = int(\x/10);
\p = (v''\i);
} else {
\p = ({45+\x/40*180+rand}:{2+rand*.2});
};}, shift={(\p)}]0pt,0pt);
\end{tikzpicture}
\end{document}