Box calculation

The box dimensions are calculated based on the images found.

In the real world, you can easyly view that for box dimension calculation you need just two not-opposed faces (Front and Left images, for example). To write a “readable” code rather than a compact one, I do the following process…

Images Hierarchy

I´m not sure if this is really needed, but I prefered to create images hierarchy or image ranks, so there are images more important than others. This is the hierarchy:

Front-Back: Front (1), Back (2)
Top-Bottom: Top (3), Bottom (4)
Sides: Left (5), Right (6)

That means, for example, that if you want to calculate box dimensions, the Front and Top images are used first. If the Front image doesn´t exist, the program attempt to calculate the dimensions using Back and Top, and so on…

Images pairs (combinations)

So, taking the images in pairs, all the combinations will be:

Original “matrix”

But since we can not calculate box dimensions using two opposite images (Front and Back, Top and Bottom or Left and Right), the previous “matrix” converts into:

Useful pairs

And since x-y pairs are exactly like y-x ones, we can clear half of the matrix:

Only unique pairs

So, it seems we can resume the box dimension calculation process to 12 different ways. But using my hierarchy, there are three “types” of images, so it´s time to define the three functions that will calculate the box dimensions deppending of wich kind of images we pass to it…

METHOD 1: FRONT(or back) – TOP (or bottom)

This method will be used for: 1-3, 1-4, 2-3, 2-4

Basically the process is:

  1. Normalize Front (or back) image, so it´s larger side will become 100 (the normalization value) and the smaller side whatever correspond.
  2. Normalize Top (or bottom) image, so it´s larger side will become the Front (or back) width and the smaller side whatever correspond.

METHOD 2: FRONT(or back) – LEFT (or right)

This method will be used for: 1-5, 1-6, 2-5, 2-6.

Basically the process is:

  1. Normalize Front (or back) image, so it´s larger side will become 100 (the normalization value) and the smaller side whatever correspond.
  2. Normalize Left (or right) image, so it´s larger side will become the Front (or back) height and the smaller side whatever correspond.

As you can see, this second method is really similar to the firs one. The only difference is we normalize the side image using the front or back´s height instead of its width.

METHOD 3: TOP (or bottom) – LEFT (or right)

This method will be used for 3-5, 3-6, 4-5, 4-6.

Actually, it’s a bit weird since we are using two not so important images to calculate box dimensions. Here we do more steps:

jadslfja ldfj aldfkj aldkfj aldskjf alksdjf alksdjf lakdjf lakjsdf lkjas
alkdfj alkdjf alkjf lakjsdf laksdj flaksdj flkasdj flkjasd lfkja sdlfkj asdfjlka
dlkha lkfha lsdhkf alksdfh alsdhf laskdhf lasdhf alsdkfh alskdhf aldskhf lasd
lkdhf aklhf lakdhf lakhd flkahsd flkahd flakhd flkahd flkha dsflkha dsf
lkdh alhf alkhdf lakdhf lakshf lafdskh

Leave a Reply