[Math] Simplest equation for drawing a cube based on its center and/or other vertices

geometry

I'm looking for the simplest equation to draw a cube based on its center and/or other verticies specified.

For example, let's say I have the 3D column vector (as I'm using OpenGL to do this):

x_3
y_1
z_4

I would like to specify and fill in its remaining vertices from this coordinate. I know there is a formula to do this for a square, albeit I can't seem to find it. If this is simply not possible (due to too little information), what's the simplest way to perform this?

Mind you, I have taken a look at this, although it appears to be dealing with 2-dimensional vertices/vectors rather than 3-dimensional ones. I'm using 3D entirely to build what I'm trying to build.

Thus, is this possible? If not, what are the minimum amounts of vertices which need to be given, along with the simplest equation to "fill in the gaps", so to speak?

Update

Common sense has revealed to me that this is impossible (duh). However, something tells me that it's possible to specify the center of a cube, along with its floating point mass, and compute the verticies from there. What is the formula for this?

Update 2

Note: the edge length of a cube and its center point are givens.

Best Answer

A cube (the one with sides parallel to coordinate axes) centered at the point $P=(x_0,y_0,z_0)$ of "radius" $r$ (and edge length $d=2r$) has vertices $V_n=(x_0\pm r,y_0\pm r,z_0\pm r)$, which could be enumerated for $0\leq n=(b_2b_1b_0)_2=\sum_{i=0}^22^ib_i\leq 7$, where $b_i=$(n>>i)&1 is the $i^\text{th}$ bit of $n$, using the bitwise shift >> and AND & operators (familiar in C-like languages & Java), as $$ V_n=(x_0+(-1)^{b_0}r,y_0+(-1)^{b_1}r,z_0+(-1)^{b_2}r). $$ The number of edges between two vertices $V_j,V_k$ would then be the bit weight of XOR$(j,k)=j$^$k$, which is also known as the hamming distance. You could emulate cube rotation by making the opposite/inverse rotation in your perspective.

As column vectors, you could write $$ P=\left[\begin{matrix}x_0\\y_0\\z_0\end{matrix}\right],\quad R_n=r\left[\begin{matrix}\pm1\\\pm1\\\pm1\end{matrix}\right] =r\left[\begin{matrix}(-1)^{b_0}\\(-1)^{b_1}\\(-1)^{b_2}\end{matrix}\right],\quad V_n=P+R_n $$ where $R_n$ are the radial vectors from the center $P$ to each vertex $V_n$. This would make it easier to rotate your cube. You'd just need a rotation matrix $M$, i.e. an orthogonal matrix (which means that its transpose equals its inverse: $M^T=M^{-1}$) with determinant $+1$ (also called special orthogonal), and then $V_n=P+M\cdot R_n$ would give you the rotated vertices.

To rotate it about an arbitrary axis, you would need a special orthogonal matrix $Q$ (for change of basis) with a unit vector parallel to the axis of rotation in say the $3^\text{rd}$ column (and the other two columns containing perpendicular unit vectors satisfying the right-hand rule), and a rotation matrix such as this, which rotates the $xy$-plane about the $z$-axis: $$ S= \left[ \begin{matrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{matrix} \right]. $$ Then you could take $M=QSQ^T$ (cf. 3D graphics approach). Another excellent method for generating rotations, recommended by @J.M. and which you may prefer, uses Rodrigues' rotation formula.

The modern computer graphics approach is usually a bit different than the matrix math of 3D linear transformations, because it uses perspective projection, which uses a $4\times4$ matrix.

Since you mention OpenGL, for a cube you might want to look some place like here or here.

Related Question