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
![0.PNG]()
- One rectangle has two inputs and two outputs
![1.png]()
- 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
![2.png]()
![3.png]()
- 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