Find the nearest set of points in 3d space

108 Views Asked by At

I have a set of 4 cuboids which are defined by 8 coordinates. The cuboids are grouped as follows (front view)

Front view of cuboids So, each of these cuboids has coordinates as shown in the table below: Coordinates Basically, I want to be able to catch the coordinates that are marked in yellow. These coordinates define the 'empty' space, defined by 8 points, that is being created within the 4 cuboids.

What I have done so far, which seems to work, is to:

  1. calculate the center point by taking the average off all X,Y and Z coordinates.
  2. calculate the deviation from each X,Y,Z to its average in absolute terms
  3. multiply those deviations for combination of X,Y,Z over X,Y,Z respectively ($\Delta_X*\Delta_Y*\Delta_Z$)

The 8 points with an identical outcome are the ones that are the closest to the center point and allow me to select the right coordinates. I don't fully understand though why this works and whether or not it will scale up to a shape which looks like this in front view: shape with 5 boxes

You can assume that all shapes are always adjacent to each other. Axis are defined as follows: Y | | .----- X / Z