Click here to Skip to main content
15,887,821 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
David19875-Aug-11 1:21
David19875-Aug-11 1:21 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff5-Aug-11 2:10
professionalBillWoodruff5-Aug-11 2:10 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
David19875-Aug-11 2:40
David19875-Aug-11 2:40 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff5-Aug-11 7:29
professionalBillWoodruff5-Aug-11 7:29 
AnswerRe: connection routing algorithm for connecting rectangles with lines ? Pin
cjb1106-Aug-11 9:35
cjb1106-Aug-11 9:35 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff7-Aug-11 13:02
professionalBillWoodruff7-Aug-11 13:02 
AnswerRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 10:48
Member 41945937-Aug-11 10:48 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? [modified] Pin
BillWoodruff7-Aug-11 14:30
professionalBillWoodruff7-Aug-11 14:30 
bw: "set of rectangle pairs => all in rectangle array 'ra, which need to be 'connected' by 1-3 line segments.">

Dave: "What determines whether you have 1, 2, or 3 line segments for a rectangle pair?"

Their position:

1. two rectangles of the same size that share either a common left, or top, can be connected with one line.

2. two rectangles, not the same size, if they share a common horizontal center, or vertical center, can be connected with one line.

3. two rectangles of same size, or variant size, which do not overlap each others bounds in such a way that two lines cannot join a center-point to the other rectangle's center-point, and that do not meet conditions 1,2 can be connected by two lines, with one 90 degree 'joint.'

4. the necessity for three lines is perhaps best expressed by an example: imagine you have r1 { 200, 200, 200, 200 } and r2 { 275, 500, 200, 200 }:

a. the shortest possible connecting line from the mid-point of the bottom of r1 to the mid-point of the top of r2 will take three lines (four points) to achieve with two 90 degree turns.

b. but, you may say, what about going from the right center-point of r1 and just drawing a first line out perpendicular to the r1's right, and then a line down so it falls on top of r2's right side. Nope, that's out, no overlapping like that allowed.

Dave: "Do the connections have to be made from top to top, left to left, or just in any order between the rectangle pairs, and can a point on one rectangle of the pair connect to more than one point on the other rectangle of the pair?"

1. No two rectangles can be connected by more than one line between them, but every rectangle can be connected to all other rectangles it has not already connected to.

2. all connection lines must originate from a mid-point on left, top, bottom, or right sides, and connect to a mid-point on the other rectangle's left, top, bottom, sides. Corners are out.

bw: "Simplest case would be a straight line: two points; then three points for a path with one right-angle turn; and, finally four points for a path with two right-angle turns."

Dave: "What do you mean "a straight line" ... 'for a path with xxx right-angle turns'?"

I mean that each line-segment of a connection can only be along a line parallel with either the horizontal or vertical axis of the graphics space, so segments can only be joined by a 90 degree rotation. Two points = straight line. Three points = two lines one of which will be at right-angles to the other. Four points = three lines, two of which will be at right-angles to each other.

bw: "Where: intersections of lines are minimized."

Dave: "I am assuming that the lines are the rectangle pair connection lines from all of the pairs in the set."

The 'set of connecting lines' I think of as a collection; each element of the collection contains 2-4 points that map to 1-3 line-segments, and some identifying information to be determined. Something like this:
XML
// will compile .NET 4.0 Client
// rough sketch for Line 'primitive'
Public class ConnectingLine
{
   public Rectangle sourceRectangle { get; set; }
   public Rectangle sinkRectangle { get; set; }
   public List<Point> cPoints { get; set; }
}

// will compile .NET 4.0 Client
// rough sketch for Line Manager Class
public static class ConnectingLines
{
   // Line Collection
   static internal List<ConnectingLine> ConnectingLineList = new List<ConnectingLine>();

   // using automatic property initializers
   public static void Add(Rectangle r1, Rectangle r2, List<Point> lPts)
   {
     ConnectingLineList.Add(new ConnectingLine
     {
       sourceRectangle = r1, sinkRectangle = r2, cPoints = lPts
     });
   }
}

// 'hard-coded' simulation of a call to add a new connection ...
// case where a connection requires 4 points that define 3 lines
// stick this in a method and call it
// will compile .NET 4.0 Client. Execute in a method body and inspect results
  ConnectingLines.Add
  (
      new Rectangle (200, 200, 200, 200),
      new Rectangle (275, 500, 200, 200),
      new List<Point> {new Point (300,400), new Point(300,450), new Point(375, 450), new Point(375,500)}
  );
In the 'solution' there would be, of course, some 'engine' analyzing the Rectangles selected to be joined, and generating the appropriate calls to ConnectingLines.Add.

Whether that 'connection engine' would make a first pass to figure out the shortest possible connection for each pair of connected rectangles, and then iterate over the complete result of the first pass, to try and identify the maximum number of overlapping connections, and then try to reduce them ... or, whether the engine would, as it created each new connection, then 'backtrack' over all the previous connections and perhaps make change them, and then compute a different choice for the current connection ... well, that's beyond my 'computer science' capacity Smile | :)

Many thanks for your detailed response !

best, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
modified on Sunday, August 7, 2011 8:48 PM

GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 15:34
Member 41945937-Aug-11 15:34 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 15:59
Member 41945937-Aug-11 15:59 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff7-Aug-11 17:40
professionalBillWoodruff7-Aug-11 17:40 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945938-Aug-11 17:57
Member 41945938-Aug-11 17:57 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff16-Aug-11 18:36
professionalBillWoodruff16-Aug-11 18:36 
QuestionRaytracing render quality [modified] Pin
Thomas.D Williams31-Jul-11 11:48
Thomas.D Williams31-Jul-11 11:48 
AnswerRe: Raytracing render quality Pin
Richard MacCutchan31-Jul-11 22:53
mveRichard MacCutchan31-Jul-11 22:53 
GeneralRe: Raytracing render quality Pin
Thomas.D Williams31-Jul-11 23:44
Thomas.D Williams31-Jul-11 23:44 
GeneralRe: Raytracing render quality Pin
David19875-Aug-11 1:07
David19875-Aug-11 1:07 
GeneralRe: Raytracing render quality Pin
Thomas.D Williams5-Aug-11 5:00
Thomas.D Williams5-Aug-11 5:00 
QuestionUnsigned Integer Mod/Remainder Pin
John Paul Walker28-Jul-11 13:11
John Paul Walker28-Jul-11 13:11 
AnswerRe: Unsigned Integer Mod/Remainder Pin
Dr.Walt Fair, PE28-Jul-11 19:18
professionalDr.Walt Fair, PE28-Jul-11 19:18 
GeneralRe: Unsigned Integer Mod/Remainder Pin
John Paul Walker29-Jul-11 13:40
John Paul Walker29-Jul-11 13:40 
GeneralRe: Unsigned Integer Mod/Remainder Pin
Dr.Walt Fair, PE30-Jul-11 17:23
professionalDr.Walt Fair, PE30-Jul-11 17:23 
AnswerRe: Unsigned Integer Mod/Remainder Pin
David198729-Jul-11 20:41
David198729-Jul-11 20:41 
QuestionHow to find estimated time remaining ? Pin
yogish29326-Jul-11 0:53
yogish29326-Jul-11 0:53 
AnswerRe: How to find estimated time remaining ? Pin
Richard MacCutchan26-Jul-11 3:00
mveRichard MacCutchan26-Jul-11 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.