Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good algorithms for drawing lines between graph nodes? [closed]

What I'm specifically grappling with is not just the layout of a graph, but when a user selects a graph node and starts to drag it around the screen area, the line has to constantly be redrawn to reflect what it would look like if the user were to release the node. I suppose this is part of the layout algorithm?

Also some applications get a bit fancy and don't simply draw the line in a nice curvy way, but also bend the line around the square shaped node in almost right angles. See attached image and keep in mind that as a node is dragged, the line is drawn as marching ants, and re-arranged nicely, while retaining its curved style.

alt text http://img260.imageshack.us/img260/5458/nodesr.png

like image 695
ApplePieIsGood Avatar asked Mar 17 '10 04:03

ApplePieIsGood


People also ask

Which is the best algorithm is used to draw a line?

Bresenham's line algorithm is a line drawing algorithm that determines the points of an n-dimensional raster that should be selected in order to form a close approximation to a straight line between two points.

How many line drawing algorithms are there?

To draw a line, you need two points between which you can draw a line. In the following three algorithms, we refer the one point of line as X0,Y0 and the second point of line as X1,Y1.

What is line generation algorithm?

DDA Algorithm also known as Digital Differential Analyzer is a algorithm for simple line generation and is explained as follows: Step 1 − Get the input of two end points. Step 2 – The difference between the two end points is calculated. dx = X1 - X0 dy = Y1 - Y0. ​x.


1 Answers

If your diagrams are not crazy full you should not need an extra-fancy algorithm for this, but just use some common sense.

  1. Cover the surface with a rectangular grid and then find a way to connect to boxes with straight lines along grid lines with a minimum number of angles: if the boxes are not on the same grid lines and you don't care where you connect you need one angle if there is no other node in between. If there are e.g. nodes in the way you need at least one more angle.

  2. As a second step for fuller diagrams add code that not only optimizes for minimal number of edges but also for minimal length of the lines. If your diagrams are not crazy full this should be hardly noticeable in terms of application response.

  3. For extra eye candy round the angles taking into account the lengths of both legs and checking for intersections with other objects on the surface. I would use 90°-pies of circles and adjust the radius of the circles (apparently not what was done above) -- for longer legs the radius should be bigger. Maybe the toolkit you are using can help you here.

like image 154
Benjamin Bannier Avatar answered Sep 22 '22 09:09

Benjamin Bannier