Find dot in the middle of the cube?

11.8k Views Asked by At

I have several cubes, those cubes have the 8 vertices, for example:

Vet   X    Y    Z

----- CUBE1 -----
(top side)
V1: -0.5  0.5  0.5
V2:  0.5  0.5  0.5
V3:  0.5  0.5 -0.5
V4: -0.5  0.5 -0.5
(bottom side)
V5: -0.5 -0.5  0.5 
V6:  0.5 -0.5  0.5
V7:  0.5 -0.5 -0.5
V8: -0.5 -0.5 -0.5

----- CUBE2 -----
(top side)
V1:  0.5  0.5  0.5
V2:  1.5  0.5  0.5
V3:  1.5  0.5 -0.5
V4:  0.5  0.5 -0.5
(bottom side)
V5:  0.5 -0.5  0.5 
V6:  1.5 -0.5  0.5
V7:  1.5 -0.5 -0.5
V8:  0.5 -0.5 -0.5

How do I find the point X, Y and Z in the center of this cube?

P.s.: the solution must be independent of the cube coordinates being positive or negative.

In this case the center of the cube1 would be (0, 0, 0) and cube2 would be (1, 0, 0)

I hope a help!

3

There are 3 best solutions below

0
On BEST ANSWER

If the cube is aligned with the axis, each coordinate only takes one of two values. All you need is, for each coordinate, to find the middle point of it.

If the cube is not aligned, you sum the 8 vectors $(x, y, z) $ that have the coordinates of a vertex and then divide by 8. This is essentially finding the "average" point, which is the center of the cube.

0
On

Just take the arithmetic average of the given coordinates to find your center. That is to say if the cube has corners at $\{(x_i,y_i,z_i)\}_{i=1}^8$ then the center is $$ \left(\frac{\sum_{i=1}^{8}x_i}{8},\frac{\sum_{i=1}^{8}y_i}{8},\frac{\sum_{i=1}^{8}z_i}{8}\right). $$

0
On

Sum the Xs, divide by 8, giving the X of the center.
Similarly, for the Ys.
Similarly, for the Zs.
This works even if the cube is not aligned with the coõrdinate planes. It also works for cuboids and parallelepipeds.