We help IT Professionals succeed at work.
Get Started

Find an algorithm to connect two rectangles

Last Modified: 2019-07-08
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.png3.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
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.
Explore More Ask a Question
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

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

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

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE