0

Firstly let me just apologise for the terrible drawings below. Very briefly what I am trying to figure out is a very robust way of counting how many boxes are touching the blue box. I have tried to create the rules for this but keep on spinning myself in circles and have resigned myself to the fact that I am not clever enough to solve it :P These boxes are in 3d dimensional space and the coordinates for the bottom left and upper right corners are known.

In this first example all the boxes are the same shape and orientation and we should be able to show that 5 boxes are touching the blue box.

Example 1: All boxes same size and orientation

However in this second example the boxes are different shapes and orientations but we would still want to show that there are now 3 boxes touching the blue box.

Example 2: Boxes of different size and orientation

Below are the mock coordinates of the bottom left (BL) and upper right (UR) corners for the second example (starting from left to right with the back red box being the last coordinate set). Can anyone show me the light and help to code up this in Python or even point me in the direction of a mathematical approach I can use?

BOX 1: BL - (0,0,0) UR - (200,50,150)

BOX 2: BL - (200,0,0) UR - (400,100,150)

BOX 3: BL - (400,0,0) UR - (450,50,300)

BOX 4: BL - (450,0,0) UR - (500,50,300)

BOX 5: BL - (200,0,150) UR - (400,100,300)

Thanks in advance!

Hillygoose
  • 177
  • 8
  • Make sure you have test cases, i.e. use test-driven development. That way you don't break existing solved cases when implementing more elaborate cases later on. – Ulrich Eckhardt Apr 01 '22 at 11:45

3 Answers3

0

Ok,

Since you know the location of the corners, you can work out the location of the other corners with simple addition and subtraction considering that the shapes are regular.

Since we have the locations of all the corners, we can create a loop that loops around all the shapes and finds out if any of the corners are inside the space of another cube.

E.G. loop 1 we have corner 1: 1,1,1 of a shape that is defined by points (1,1,1), (1,2,1) etc

with corner 1, we simply take that point (1,1,1) and compare it to the ranges of points that the other cubes contain. for instance we compare it to other cube 1:

our point: 1x,1y,1z

other cube 1 area: 1 to 2x, 1 to 2y, 1 to 2z

from this we can see that out point fits the criteria of being inside the shape. I.e. 1,1,1 is a valid coordinate inside the other cube.

If you are new to 3d stuff, i would recommend using a library that handles 3d shapes without you having to do any maths like this. think about how you would google for a library like that, and where you want the code to run.

best iwshes

  • Touching means no intersection – Alexey S. Larionov Mar 31 '22 at 15:42
  • This is easily fixed by adding a version of my scribblings above which increases the size of the box we search for. if you search using points which are translated to be slightly larger than the box itself you can find things that are, for instance in the coordinate next to the box eg: 1,0,0 is next to 0,0,0. To get things that are 'touching' you would expand the 'search box' by one coordinate in all directions – Other Cube Apr 01 '22 at 12:59
0

As I see it, there are 3 cases of "touching" (not intersection):

  1. A red box touches the blue box with a corner. To check it you need to iterate all red box's vertices, and check if any of them belongs to any of blue box's triangles (12 of them). You can implement such check using this question

  2. A red box touches the blue box with an edge. It can only happen if any red box's edge intersects any of blue box's edges. Use this question to implement lines intersection in 3D

  3. A red box touches the blue box with a side. I think it's safe to say that it's sufficient to check if any red box toches the blue using steps (1) and (2) above, and checking if the blue box touches any red box using steps (1) and (2) above

Alexey S. Larionov
  • 6,555
  • 1
  • 18
  • 37
0

It seems that touching in 3 dimensions means that the boxes touches on every 2d projection. Deciding if two boxes touch on a 2d plane seems easy enough & doing the projections should be easy regarding the other answers.

For instance on your second figure, you can certificate that the blue box does not touch the rightest one with a projection on the (0xy) plane.

Qise
  • 192
  • 6