# Is it possible to draw a curved edge between two vertexes of a graph? [duplicate]

The following code generates a graph.

LayeredGraphPlot[
{{"i" -> "m", 1}, {"i" -> "...", 1}, {"i" -> "n", 1}, {"m" -> "j", 2}, {"..." -> "j", 2}, {"n" -> "j", 2}},
DirectedEdges -> True,
VertexLabeling -> True,
PlotStyle -> {FontSize -> 14},
EdgeRenderingFunction -> (Switch[#3, 1, {Dashed, Arrow[#1, .1]}, 2, {Arrow[#1, .1]}] &)]


My question is that is it possible to draw curves between "i" and each of "m", "...", "n" instead of straight lines, like the red curve below? Thank you.

• You are already using the EdgeRenderingFunction with Arrow. All you need to do is use a function that makes curved lines instead of Arrow. Dec 28, 2014 at 2:54
• @Szabolcs Thanks for the reply. I know there is something like BSplineCurve (reference.wolfram.com/language/ref/Arrow.html), but I don't know how to apply it in this situation.
– Tony
Dec 28, 2014 at 3:01
• Also related: mathematica.stackexchange.com/a/11704/57 Dec 28, 2014 at 11:05
• May 1, 2015 at 18:46

You can construct a BezierCurve by adding two control points to the list of vertex coordinates for the two vertices (p[[1]] and p[[2]]) incident to an edge.

In the following function bC with three arguments ({t1,t2,t3}), the two additional points are obtained by taking two points on the line joining the two vertex coordinates, t1 p[[1]] + (1-t1) p[[2]] and t2 p[[1]] + (1-t2) p[[2]] where 0<= t1, t2 <=1, and adding to these points {0,t3} or {t3,0} to ensure that the resulting four points are not collinear. The default values for the three arguments are {t1,t2,t3}= {1/3,2/3,1/3}.

ClearAll[bC]
bC[t1_:(1/3),t2_:(2/3), t3_:(1/3)]:= With[{p=#},
BezierCurve[{p[[1]],
t1 p[[1]]+(1-t1)p[[2]]+If[p[[1,1]]==p[[2,1]],{t3,0},{0,t3}],
t2 p[[1]]+(1-t2)p[[2]]-If[p[[1,1]]==p[[2,1]],{t3,0},{0,t3}],
p[[2]]}]]&;

LayeredGraphPlot[ {{"i" -> "m", 1}, {"i" -> "...", 1}, {"i" -> "n", 1},
{"m" -> "j", 2}, {"..." -> "j", 2}, {"n" -> "j", 2}},
DirectedEdges -> True, VertexLabeling -> True,
PlotStyle -> {FontSize -> 14},
EdgeRenderingFunction -> (Switch[#3, 1, {Dashed,Arrow[bC[][#],.1]}, 2, {Arrow[#1, .1]}] &)]


• Why did you reopen this question, please? Apr 8, 2015 at 23:00
• @Mr.Wizard, I was puzzling over why this q/a was reopened and appeared with a "modified by kguler" tag. I must have inadvertently clicked the reopen button. Sorry.
– kglr
Apr 8, 2015 at 23:16
• That's okay. It just surprised me as I didn't see any precipitating comments or recent edits. Why don't you close it now? I think this was the previous duplicate if I am reading the timeline correctly. Apr 9, 2015 at 0:57
• Mr.Wizard, how come my accidental click made the previous close votes and links disappear?
– kglr
Apr 9, 2015 at 1:01
• You have the Gold tag badge for plotting (and list-manipulation) which gives you moderator-like single vote power to close (and apparently reopen) duplicates in this tag. Use it wisely. :-) (Possible duplicate: comments are automatically deleted when the close occurs.) Apr 9, 2015 at 1:22