2

I'm using TikZ to show Prim's algorithm, like in this example on texample.net.

screenshot

How can I get TikZ to create bended edges instead of the straight ones here?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Chris
  • 21
  • 1
  • 2
  • 2
    I'm afraid I can't help with TikZ (never used it); however, you might be able to find an answer on http://tex.stackexchange.com/. – bcat Nov 07 '10 at 00:35
  • Other way to bend a segment (not really an answer): \begin{tikzpicture}[thick] \draw [blue] plot [smooth,tension=2] coordinates {(0,0) (6,-.3) (12,0)}; \draw [red] plot [smooth,tension=.5] coordinates {(0,0) (6,-.3) (12,0)}; \draw (0,0) -- (12,0); \end{tikzpicture} – MattAllegro Jul 04 '15 at 15:40

2 Answers2

1

The problem with bent edges, is that it takes some knowledge of the angle that the line makes with the two nodes. When you know this you can use the in and out directives in the to form of the path or draw command. Since you are doing these connections in a loop over nodes, you were hoping to ignore explicitly calculating these angles and letting TikZ take care of drawing the lines. If you need to though, those are the commands you are most likely going to need to utilize. Good luck.

Joel Berger
  • 20,180
  • 5
  • 49
  • 104
1

You can use the bend <direction> option to bend arrows in some arbitrary direction. Like this: \path[edge] (\source) to[bend right] node[weight] {$\weight$} (\dest); (from your example)

There are additional options you can use to change the arc and stuff of the bend but you will have to check the manual for that ;)

Maigo
  • 69
  • 4