1

Given 8 points in $\mathbb{R}^3$ and the prior knowledge that these points form the vertices of a cuboid, what is a computationally efficient way to order them?

When I say "cuboid" I refer to the set of all achievable shapes when starting from the canonical unit cube centred on the origin and applying independent scaling in x,y, z, then rigid rotation, then translation.

When I say "order", I mean that I want to know the relationships between all the vertices. For instance, with the ordering convention below, I can always say that vertex 1 is connected to vertices 2, 4, and 5 via an edge, and this remains true no matter what cuboid preserving transformation I apply to the points.

enter image description here (furthest face from the viewpoint is shaded)

I've come up with a bunch of ideas that don't seem elegant, like computing euclidian distances and computing dot products of vectors formed by pairwise combinations of the points. I'm just wondering if there is an "elegant trick" out there.

  • 1
    Try binary labels: $000$, $001$, $010$, $011$, $100$, $101$, $110$, $111$. – Blue Dec 22 '21 at 11:34
  • @Blue Oh, so for a 2d quadrilateral I could move all 4 points such that their centroid is at (0, 0), then I could give them a 2 bit representation based on whether they are in +/-x and +/-y. Right? Then "adjacent" points are a hamming distance of 1 away from each other..? – Alexander Soare Dec 22 '21 at 11:37
  • 1
    Moving the centroid to the origin and checking signs will do it. Alternatively: Move a corner to the origin and (taking the side-length to be one) the opposite corner to the "all $1$s" point. Then, the binary coordinates are just the concatenations of the Cartesian coordinates. ... And, yes: Hamming distance tells you how points relate to each other. – Blue Dec 22 '21 at 11:40
  • @Blue in your last comment I suppose the first step would be to apply a rotation, scaling, and translation to make the "canonical" quadrilateral (but then I'd need some way of computing the transformation). Then because I still know the indices of the vertices in my initial list of 8 vertices I still don't lose the relevant information. – Alexander Soare Dec 22 '21 at 11:44
  • Correct. The transformation is pretty straightforward. Translation to get a vertex to the origin is easy. Then, build a matrix with unit vectors to the adjacent-to-origin vertices; the rotation is just the inverse of this matrix (since the matrix of the final cube should be the identity matrix, and the rotation is an orthogonal transformation). Then scale appropriately in each coordinate direction. – Blue Dec 22 '21 at 11:51
  • @Blue yes but that's assuming I know which are the adjacent-to-origin vertices. If I knew that I'd be already done no? – Alexander Soare Dec 22 '21 at 11:52
  • I guess I misunderstood the question. Sorry. ... You're saying that you have eight vertices of a cuboid and need to determine how exactly they're connected. (I thought you were just looking for a labels to the vertices that helped encode the already-known relations.) That's a trickier problem and will require more thought. ("Extended discussion" warning. This may be my last comment. If I have a proper solution, I'll post it as an answer.) – Blue Dec 22 '21 at 11:57
  • 1
    Likewise re extended discussion. But I thought we had it before you suggested the alternative. Once translated to the origin, we take the dot product with each plane of the co-ordinate system and use the sign of the result to determine the binary bit (treat 0 as -+ve). Will await your answer (or absence of one). Thanks for your help so far! – Alexander Soare Dec 22 '21 at 12:01
  • 1
    If the cuboid is arbitrarily-rotated, there's no guarantee that simply moving the centroid to the origin puts one vertex in each quadrant/octant/orthant. (Consider a long, thin rectangle centered on the line $y=x$. This has two vertices in the First Quadrant, and two in the Third Quadrant.) – Blue Dec 22 '21 at 12:07
  • 1
    This is a different question, but might be helpful to look at. The comments to that question contain some further links. – Will Orrick Dec 22 '21 at 12:22
  • 1
    Can you define "cuboid"? Some usages of the term are quite general, others less so. – Will Orrick Dec 22 '21 at 12:41
  • @WillOrrick done – Alexander Soare Dec 22 '21 at 12:44

3 Answers3

1

The following method works for arbitrary parallelepipeds. The faces don't have to be rectangular.

Pick an arbitrary non-zero vector $u$ and compute the dot product of $u$ with each of the eight corner vectors. Unless you are unlucky, the eight dot products will all be different. Now the least dot product and the greatest dot product correspond to corners that are diagonally opposite each other along the line through the body center. The same goes for the second least and second greatest, the third least and third greatest, and so on. So you pair up the corners in this way.

Now translate so that the corner $a$ with least dot product is at the origin. The corresponding change in the dot products is to subtract the least dot product from all of them, so that the least dot product $u\cdot a$ is now $0$ and all others are positive. The two smallest non-zero dot products correspond to corners that are neighbors of $a$; the corners paired with these two are non-neighbors of $a$.

This leaves one pair. One member of that pair will be the sum of the two corners identified as neighbors of $a$ and the other member will be the third neighbor of $a$.

That the two smallest positive dot products correspond to neighbors of $a$ follows from the positivity of the dot products: if $b$, $c$, and $d$ are the neighbors of $a$ (which has been shifted to zero) and $d$ has the greatest dot product among these, then $(b+c)\cdot u$, $(b+d)\cdot u$, $(c+d)\cdot u$, and $(b+c+d)\cdot u$ are certainly all greater than both $b\cdot u$ and $c\cdot u$.

Will Orrick
  • 18,220
1

Building on Will's answer, a simple approach if the cuboid is known to be a cube. Take one point, call it 1, and two further points A and B as before. Define 1 to be the origin for vectors $a$ and $b$ to A and B. Let $c = b - a$.

Calculate $\left\|a\right\|:\left\|b\right\|:\left\|c\right\|$. This can be:

  • $1:1:1$
    Both A and B are 2-connected to 1. The cube has side $\frac{\left\|a\right\|}{\sqrt{2}}$.

  • $1:1:\sqrt{2}$
    Then the triangle formed by 1, A and B is wholly contained in one face (A and B are 1-connected to 1 or A is 1-connected and B is 2-connected on the same face). Wherever the long side is distinguishes the two cases. The cube has side length $\left\|a\right\|$

  • $1:\sqrt{2}:\sqrt{3}$. The triangle contains opposite corners of the cube (A or B is 3-connected to 1). The cube has side length $\left\|a\right\|$.

  • Permutations of the above.

It remains to determine the orientation of the faces, which is done by checking against one further point.

So we only have to select three points and calculate three lengths. Comparing the ratios of the lengths directly gives us the the configuration of the cube, one further point yields the orientation.

AlDante
  • 302
  • 1
  • 10
  • Nice. My head is filled with cotton as I'm down with a fever, but it seems to me this would only work with cubes (ie all side lengths are the same)? So if all side lengths are not the same, we don't really know which ratios to look for. Your second bullet point could by chance look like 1:1:1 just because of the specific dimensions of the cuboid – Alexander Soare Dec 23 '21 at 13:40
  • Me, I'm recovering from a 'flu, head full of cotton wool, which is why I have been trying to solve a cube, not a cuboid. Sorry, you are absolutely right, this only works as written for a cube. I will have a look to see if the principle, i.e. classifying triangles, works for general cuboids. – AlDante Dec 23 '21 at 15:22
0

Let us say that two points are:

  • 1-connected if they define an edge in your cube (e.g. 1 and 2).
  • 2-connected if they are opposite corners of a face (e.g. 1 and 3).
  • 3-connected if they are opposite corners of the cube (e.g. 1 and 7).

Pick a point, which we will call 1. Pick two further (distinct) points. These can be

  • both 1-connected (with vertex 1). Then they define a face of the cube and you have all further relationships, because the side length of the face yields the offset to the remaining points.
  • one is 1-connected and one is 2-connected. These either define a face or an interior triangle of the cube where one edge is the cube diagonal and 1 is not on this edge.
  • one is 1-connected and one is 3-connected. The two vertices define a face and the 1-connected edge is perpendicular to this face. The interior triangle is formed by the cube diagonal, one edge (connected to 1) and a face diagonal.
  • both are 2-connected. The two vertices define a face and their diagonals with 1 define two further faces. They also define a tetrahedron.
  • one is 2-connected and one is 3-connected. The two vertices are on the same edge (not connected to one)and the interior triangle is formed by this edge, a cube diagonal (containing 1) and a face diagonal.

By looking at distances and the interior triangles you can determine which case applies and derive the structure of the cube.

Although this only looks at three points (plus possibly more to check which configuration we have) I think it is a lot more complicated than the Euclidean distance method described here.

AlDante
  • 302
  • 1
  • 10
  • Thanks for the response. I think it's a sound approach. I will leave this question open though, as I want to see if there are any other solutions with fewer steps. – Alexander Soare Dec 22 '21 at 12:47
  • 1
    I personally don't think it's the way to go - although you only work with three points, the configuration check is complicated. The Euclidean distance method will be faster, in my opinion, and a lot easier to get right.

    The only thing my suggestion has going for it is that it only accesses three points. If this is computationally expensive for some reason, then it might be worth a look. But with only eight points in total, saving five at the cost of complicated calculations is in general not going to be worth it.

    – AlDante Dec 23 '21 at 07:18