# Width of a tilted cube

I'm projecting a cube onto a hexagon (for RGB to HSL conversion) and I want to calculate the width of the hexagon.

Cube is, first, tilted by 45° ccw on the x axis, and then, tilted by 35.26° ccw on the y axis. Black corner is at the bottom and the white corner is at the top. Both (black and white) corners pass through the z axis.

I have four values at hand, but don't know what to do with them, atm. I can get the width of the hexagon with this 3D software, but I need to be able to calculate it mathematically.

• With the annotated angles I don't think you'll have a regular hexagon. Use $60°$ and $30°$. – N74 Aug 26 '16 at 18:03
• @N74 These angles give the desired result. Perhaps the image I've provided or my explanation wasn't clear. I can post another image. – akinuri Aug 26 '16 at 18:21
• If the hexagon is exactly like the one to the left of the picture you are on the right way. But that is not a regular hexagon, with all angles congruent. – N74 Aug 26 '16 at 22:29
• This might help. I'm explaining the projection process. – akinuri Aug 27 '16 at 8:13
• If you want to draw an hexagon, forget the projections. Start with blue point at coordinates (0, 0), the black point will be at coords (0, -1). The green point will be at coords (-.866, -.5) and the red at (.866, -.5). The cyan point will be at coords (-.866, .5) and the magenta at (.866, .5). Finally the white point will be at (0, 1). The values are $.5=\sin 30°=\cos 60°$ and $.866=\sin 60°=\cos 30°$. To scale with RGB values multiply by 255 (and eventually translate to center the image). – N74 Aug 27 '16 at 11:37

Based on your technical drawing with measurements posted in it, the width $H$ of the hexagon can be deduced with simple trigonometry: $$H = 360.62\cos\,(54.74^\circ) + 255\cos\,(35.26^\circ).$$

And in general, for any angle $\theta$ that you tilt the cube of side length $w$ and face-diagonal length $\sqrt 2 \cdot w$ over, the width $H$ of the hexagon will be $$H = \sqrt 2 \cdot w\cos\,(\pi/2 - \theta) + w\cos\,\theta.$$

• I'll be doing the calculation in JavaScript and my trigonometry knowledge is limited. How would I write 360.62cos(54.74°)? This 360.62 * Math.cos(54.74)? That doesn't give the correct width. – akinuri Aug 26 '16 at 17:23
• @akinuri, Since JS uses radians instead of degrees, you'll first have to convert your degrees into radians. There is a function for doing this on this question: stackoverflow.com/questions/9705123/… – Alex Ortiz Aug 26 '16 at 17:26
• Ah, yes, sorry. My bad. I knew that. Working now :) – akinuri Aug 26 '16 at 17:28
• For this particular problem, you do not need trigonometry. Just the formula $\text{(width)} = 2 \text{(edge)} \sqrt{2/3}$. – Futurologist Aug 26 '16 at 18:10

What you are saying is that basically one of the cube 3D diagonals, connecting the what-you-call-white vertex to the opposite black vertex, is aligned with the $z$ axis and you are looking at the shadow the cube casts on the $x,y$ plane projected along light rays parallel to the $z$ axis.

Let $O$ be the origin of the coordinate system and thus it is the lowest vertex of the cube. Let the highest vertex is $O'$ which is the opposite to $O$ across the center of the cube. $OO'$ lies on the $z$ axis. Now let $A, B, C$ be the three vertices of the cube immediately attached by edges to $O$. That is $OA, OB, OC$ are the three pairwise orthogonal edges meeting at $O$. Similarly, let $A', B', C'$ be the three pairwise orthogonal edges meeting at $O'$.

Assume all the edges of the cube have length $a$. Now, the planes $ABC$ and $A'B'C'$ are orthogonal to the diagonal $OO'$ i.e. they are orthogonal to the $z$ axis and thus parallel to the $x,y$ plane. The two triangles $ABC$ and $A'B'C'$ are equilateral triangles with edgelength $a\sqrt{2}$. Therefore the orthogonal projection $A_1B_1C_1$ of $ABC$ is also a congruent equilateral triangle of edge length $a\sqrt{2}$. The same is true for the projection $A'_1B'_1C'_1$ of $A'B'C'$. The two equilateral triangles $A_1B_1C_1$ and $A'_1B'_1C'_1$ share a common center, the point $O$ and are related to each other by a rotation of angle $\pi$ (180 degrees). The shadow of the cube is the regular hexagon spanned by the points $A_1C'_1B_1A'_1C_1B'_1$ and you know the length of the segment $A_1B_1 =a \sqrt{2}$. Since triangle $A_1B_1A'_1$ is right angled and the diagonal of the hexagon $A_1A_1' = 2 B_1A'_1 = 2x$ (the latter is the edge of the hexagon). Therefore, by Pythagoras' theorem $4x^2 - x^2 = 2a^2$ which means that $x = a\sqrt{\frac{2}{3}}$ is the edge of the regular hexagon (the projection of the cube). Then, the diagonals of the hexagon are of length $2x = 2 a\sqrt{\frac{2}{3}}$, which is also the diameter (the width) of the hexagon you are looking for.

In your case, for a cube of edge-length $a=255$, the width of its projection is $$2 \cdot 255 \cdot \sqrt{\frac{2}{3}}=416.41325627314...$$

The width of the hexagon can be calculated by cosine of the angles.