BrainDen.com - Brain Teasers
• 0

# A plane old stuffed cube

## Question

What is the area of the largest square that can fit entirely within a unit cube?

## Recommended Posts

• 0

If no one else is going to go after this one... I can give an answer based on, well, working in the spirit of the best solution the program could find. But I can't prove that there aren't any larger squares that can fit in the unit cube.

Imagine a placing the vertices of the square as shown in the picture -- points A and B are distance x from the corner on the bottom face of the cube, and points C and D are distance x from the opposite corner on the top face of the cube.

The length of edge AB will be

sqrt(x2+x2) = x sqrt(2)

If you were to superimpose the top face onto the bottom face (sort of squishing the cube down onto a plane) then the distance from B to C after squishing would be

(1-x) sqrt(2)

The total distance from B to C in three dimensions would also take into account that the top face and the bottom face are 1 unit apart, so the total distance would be

sqrt(12 + [(1-x) sqrt(2)]2)

We need to find the value of x for which those are equal -- meaning that edge AB is the same length as edge BC as you should have in a square. Solving...

x sqrt(2) = sqrt(12 + [(1-x) sqrt(2)]2)

2x2 = 1 + [(1-x) sqrt(2)]2

2x2 = 1 + 2(1-x)2

2x2 = 1 + 2 - 4x + 2x2

0 = 3 - 4x

x = 3/4

So the edge length for AB would be

x sqrt(2) = 3/4 sqrt(2)

Checking my math, solving for the edge length of BC would be

sqrt(1 + [(1-x) sqrt(2)]2)

when x = 3/4 which thankfully also gives 3/4 sqrt(2)

The square's area would be

[3/4 sqrt(2)]2 = 9/16 2 = 18/16 = 1.125

##### Share on other sites

• 0

I just realized where I went wrong in my first guess... I'll have to figure a different answer:

I just realized I can't use the unit edge length (a square would be the cube face) or the diagonal of the cube face (creates a rectangle with the cube edge). The correct square would be between those two lengths. Mathematically defining that length is the challenge.

Edited by Dariusray
##### Share on other sites

• 0

The square will need to stretch from one cube corner to the opposite cube corner this means that the other corners of the square rest on an edge half way up a cube.

Using Pythagoras gives use sqr(.5*.5 + 1*1) for a side of this square.

which gives us 1.25 units squared for the area

I am not sure if this is a square or a rhombus however. I suspect the latter given that the distance from cube corner to cube corner is greater than the distance between cube edge and cube edge. I'm sure however whoever reads this answer could from this enlighten us.

##### Share on other sites

• 0

I just realized where I went wrong in my first guess... I'll have to figure a different answer:

I just realized I can't use the unit edge length (a square would be the cube face) or the diagonal of the cube face (creates a rectangle with the cube edge). The correct square would be between those two lengths. Mathematically defining that length is the challenge.

Since it's a unit cube, your answer simplifies (if I'm reading it correctly) to Sqrt(2) / 2 = .707.

This is smaller than a cube face. But maybe I don't interpret your answer correctly.

##### Share on other sites

• 0

The square will need to stretch from one cube corner to the opposite cube corner this means that the other corners of the square rest on an edge half way up a cube.

Using Pythagoras gives use sqr(.5*.5 + 1*1) for a side of this square.

which gives us 1.25 units squared for the area

I am not sure if this is a square or a rhombus however. I suspect the latter given that the distance from cube corner to cube corner is greater than the distance between cube edge and cube edge. I'm sure however whoever reads this answer could from this enlighten us.

A little too large, but close. And the answer is in fact a rational number.

If it helps, there is a close relation to the question that asks whether a cube can be pushed through a square hole in a smaller cube.

##### Share on other sites

• 0

So far the best that my horribly inefficient and possibly buggy java code came up with is an area of 1.0984. But it's still running.

I probably ought to have searched for a reasonably efficient Windows C compiler instead.

Unfortunately I don't see any easy way of modifying the code to work in 4 dimensions. Especially since it uses cross products which I don't think are defined in 4D.

##### Share on other sites

• 0

This is what my brute force approach came up with. If you look at the coordinates of the square that it fit into the unit cube, it should become clear how to imagine that it's oriented, and allow you to come up with a more analytical approach to solving the problem. Which I'm not going to attempt myself for now.

A: 0.0 0.0 0.27999999999999997
B: 0.0 0.7800000000000004 0.9800000000000005
C: 0.997834284225222 0.9940718358648026 0.7414628114649353
D: 0.997834284225222 0.21407183586480227 0.041462811464934746
Edge length AB: 1.0480458005259128
Edge length AC: 1.4821605850919133
Edge length BC: 1.0480458005259128
Edge length BD: 1.482160585091913
Edge length CD: 1.0480458005259128
(The program also printed the length of each of the edges and diagonals, for debugging purposes.)

```class SquareInCube {

// A, B, C, and D are coordinates of the square's corners
static double[] A = {0,0,0};
static double[] B = {0,0,0};
static double[] C = {0,0,0};
static double[] D = {0,0,0};
// CrossProd values will be used to place point C
static double[] CrossProd1 = {0,0,0};
static double[] CrossProd2 = {0,0,0};
static double stepsize = 0.02;
static double largesthit = 1;

// calculates the distance between two points
static double Dist(double[] Point1, double[] Point2) {
return Math.pow(
Math.pow(Point1[0]-Point2[0], 2) +
Math.pow(Point1[1]-Point2[1], 2) +
Math.pow(Point1[2]-Point2[2], 2) , 0.5);
}

// calculates the cross product of two vectors
// the first two parameters are the vectors to be cross-producted
// the third parameter is the array that will hold the answer
static void CrossProduct(double[] Vec1, double[] Vec2, double[] Answer) {
Answer[0] = Vec1[1] * Vec2[2] - Vec1[2] * Vec2[1];
Answer[1] = Vec1[2] * Vec2[0] - Vec1[0] * Vec2[2];
Answer[2] = Vec1[0] * Vec2[1] - Vec1[1] * Vec2[0];
}

// places a point in the unit cube
//   systematically places it at each point, increasing by stepsize
// when it's moving point A, it will keep it restricted to the area
//   from (0,0,0) to (0.5,0.5,0.5) to minimize the search area and
//   increase efficiency
// when it's moving point B, it will put it anywhere in the unit cube
// returns true if it places it at a new point
// returns false if it has already placed it at every point
static boolean MovePoint(double[] Point, double maxval) {
for(int i=0; i<3; i++) {
Point[i] += stepsize;
if(Point[i]<maxval) return true;
Point[i] = 0;
}
return false;
}

// moves point B to a point in the unit cube where the distance is
//   at least largesthit from point A
// returns true if it was able to place point B
// returns false if it was not
static boolean MoveB() {
boolean succeeded = true;
do {
succeeded = MovePoint(B,1);
} while(succeeded && Dist(A,B)<largesthit);
return succeeded;
}

// figures out where to place point C
//
// this first function just does calculations to find
//   cross products needed to place point C, but doesn't
//   actually place point C yet
// it calculates CrossProd1 as the cross product of a vector
//   from A to B and a vector from the origin to B
//   to produce a vector perpendicular to the line A-B
// if that cross product is small in magnitude, it uses the
//   vector from (1,0,0) to B instead of the origin to B
// then it calculates CrossProd2 as the cross product of
//   the vector from A to B and CrossProd1
// then normalizes both of them to Dist(A,B)
static void CrossProdsC() {
double[] AtoB = {B[0]-A[0], B[1]-A[1], B[2]-A[2]};
double[] OZZtoB = {-B[0], B[1], B[2]};
double[] Zero = {0,0,0};
double magCP1 = 0, magCP2 = 0;

CrossProduct(AtoB, B, CrossProd1);
if(Dist(Zero,CrossProd1)<0.1)
CrossProduct(AtoB, OZZtoB, CrossProd1);
CrossProduct(AtoB, CrossProd1, CrossProd2);

magCP1 = Dist(Zero, CrossProd1);
magCP2 = Dist(Zero, CrossProd2);
for(int i=0; i<3; i++) {
CrossProd1[i] *= Dist(A,B) / magCP1;
CrossProd2[i] *= Dist(A,B) / magCP2;
}
}

static boolean PlaceC(double rotate) {
boolean succeeded = true;
for(int i=0; i<3; i++) {
C[i] = B[i] +
CrossProd1[i] * Math.sin(rotate) +
CrossProd2[i] * Math.cos(rotate);
if(C[i]<0 || C[i]>1) succeeded=false;
}
return succeeded;
}

static void PlaceD() {
D[0] = A[0] + (C[0]-B[0]);
D[1] = A[1] + (C[1]-B[1]);
D[2] = A[2] + (C[2]-B[2]);
if(D[0]>0 && D[0]<1 &&
D[1]>0 && D[1]<1 &&
D[2]>0 && D[2]<1) {
PrintResult();
largesthit = Dist(A,B);
}
}

// prints the coordinates and edge length
static void PrintResult(){
System.out.println("A: "+A[0]+" "+A[1]+" "+A[2]);
System.out.println("B: "+B[0]+" "+B[1]+" "+B[2]);
System.out.println("C: "+C[0]+" "+C[1]+" "+C[2]);
System.out.println("D: "+D[0]+" "+D[1]+" "+D[2]);
System.out.println("Edge length AB: "+Dist(A,;
System.out.println("Edge length AC: "+Dist(A,C));
System.out.println("Edge length BC: "+Dist(B,C));
System.out.println("Edge length BD: "+Dist(B,D));
System.out.println("Edge length CD: "+Dist(C,D));
System.out.println(" ");
}

// this will place the point A with the MovePoint function
//   point A will be moved systematically throughout a "quadrant" of the
//   unit cube from the origin to point (0.5,0.5,0.5)
// then it places point B with the MoveB function
//   so it will be placed at a distance of at least largesthit from point A
// then it places point C using CrossProdsC once to calculate values of
//   CrossProd1 and CrossProd2 that will be used to make an orthogonal circle
//   for the given coordinates of A and B, then PlaceC to place point C somewhere
//   on that circle
// then it places point D
// the function PlaceD handles printing the output and updating largesthit
//   if point D lies within the unit cube
public static void main(String[] args){
while(MovePoint(A,0.5)) {
while(MoveB()) {
CrossProdsC();
for(double rotate=0; rotate<2*Math.PI; rotate+=stepsize) {
if(PlaceC(rotate)) {
PlaceD();
}
}
}
}
}
}```
Most people would probably think it's easier to install the NetBeans IDE and program through it, but not me
If you do use NetBeans, be sure to leave the package line at the top when you create a new project, and just cut/paste my code to replace everything after that line
There's a tutorial on Oracle's website about using NetBeans. The rest of this is if you want to do things the old fashioned way.
Set the path variable so it includes Java's bin directory. Exactly where things are will vary a little based on your Windows version but...
- This can usually be done from the control panel,
- go to System,
- find a button to access Environment Variables,
- edit the Path variable: keep everything that's already there but add the directory for the binary files, separated from the others by a semicolon
- the path to add should be something like C:\Program Files\Java\jdk1.7.0_40\bin
Copy and paste the code above into a text file and save it someplace like C:\Java\squareincube.java
Open a command line prompt and go to the directory where you saved the .java code.
Compile the java code to make the .class file. (Use the javac command, like "javac squareincube.java")
Run the program. (Type "java SquareInCube". Capitalization matters.)
##### Share on other sites

• 0

Thanks for the programming detail.

I'm learning how to do java programming.

You get an area of 1.0984, a rational number.

But it can be bigger than that.

##### Share on other sites

• 0

I'm late marking this one solved. Nice, clear approach.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.