As seen here, i am trying to link the circles and draw a square somewhere at midpoints on each of the links. But the problem is that some of the squares overlap.
Is there any way that i can detect those overlaps and re-position or move those squares so that they remain on their respective link and do not overlap.
Here is the code
int x1 = 100, x2 = 500, aIncr = 50, bIncr = 50;
int y1, y2;
y1 = y2 = 100;
g.setColor(Color.GRAY);
for (int i = 0; i < column1.length; i++) {
g.fillOval(x1, y1, column1[i], column1[i]);
y1 += aIncr;
}
for (int i = 0; i < column2.length; i++) {
g.fillOval(x2, y2, column2[i], column2[i]);
y2 += bIncr;
}
y1 = y2 = 100;
int squareWidth = 20;
int x, y;
for (int i = 0; i < column1.length; i++) {
y2 = 100;
for (int j = 0; j < column2.length; j++) {
g.drawLine(x1 + column1[i] / 2, y1 + column1[i] / 2, x2 + column2[j] / 2, y2 + column2[j] / 2);
x = ((x1 + column1[i] / 2) + (x2 + column2[j] / 2)) / 2 - squareWidth / 2;
y = ((y1 + column1[i] / 2) + (y2 + column2[j] / 2)) / 2 - squareWidth / 2;
g.fillRect(x, y, squareWidth, squareWidth);
y2 += bIncr;
}
y1 += aIncr;
}