Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatic analysis of geometric shapes

I’m trying to work out a math / geometry problem in a Java project I’m working.

Here is the scenario:

There are two sets of blocks, each with a different number of blocks and different dimensions. In this example Set A has 5 blocks, each is 20x20 pixels; Set B has 6 blocks, and each is 25x50 pixels:

5 blocks of 20x20

I’m trying to come up with a way to mathematically or logically determine how those sets would line up to maximize the contact between them. If you were to line these set up end-to-end it would look like this:

Four of the 25x25 blocks touch the 5 20x20 blocks

In this image, 4 of the blocks in set B are in contact with the blocks in set A. However, if you shift set A to the right a bit, you can get 5 of the blocks in set B to touch:

The problem is that the formula / algorithm / logic needs to be flexible enough to handle different combinations. In this example, set C has only 3 blocks, and each block is 40x40:

All 5 25x25 blocks touch the 40x40 blocks

Any ideas?

like image 603
rearden Avatar asked Oct 31 '22 08:10

rearden


1 Answers

Center the two sets of blocks and shift one of them by a small amount.

like image 75
Yves Daoust Avatar answered Nov 15 '22 04:11

Yves Daoust