We help IT Professionals succeed at work.
Private

# Find an algorithm to connect two rectangles

on
214 Views
I'm trying to figure out an algorithm for the following problem:

- There should always be two rectangles connected to a line
- The lines always run from the middle of the rectangle1 to the center of the rectangle2
- One rectangle has two inputs and two outputs
- An output can only be connected to one input
- An input can only be connected to one output
- The first rectangle has a connection from the output to the input
- You can move the rectangles as you like
- All lines must be outside the rectangles
- The lines may intersect

My idea is to always compare two rectangles. The left and the right rectangle.
I first determine the left rectangle of the two rectangles.
Then I ask if the left rectangle is above or below the right rectangle and draw the lines accordingly

In addition, I still have to query whether the center of the smaller rectangle is within the larger rectangle and draw the lines, then different.

My questions:
1) Is this algorithm feasible under these conditions?
2) What else do I have to keep in mind about my algorithm, or do you have ideas for a better algorithm?

I am very grateful for numerous tips
Comment
Watch Question
This question hasn't been answered yet.
While you wait, find out how you can maximize your capability with the most trusted tool in IT.
###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant