Projecting a hypercube onto a hyperplane

88 Views Asked by At

This task involves projecting a 4-dimensional hypercube onto a hyperplane (ie a 3-dimensional space).

Let the hypercube have its vertices at the points (±1, ±1, ±1, ±1), where all 16 vertices are obtained by using all combinations of plus and minus signs. The hyperplane to be projected to must have the fourth dimension coordinate 0 (in analogy with 3D, the xy plane is the plane where the third dimension coordinate z = 0).

The projection must be a so-called oblique projection along a vector U from the vertices to a point in the hyperplane. One way to solve it is to go from a corner of the hypercube along the vector U until you reach the hyperplane (the one with the fourth coordinate equal to zero).

Use the vector U = (2, 3, 4, 5).

Report the 3-dimensional coordinates that the corners of the hypercube get after the projection and draw the projected hypercube in a figure with edges between nearby corners. Remember that there are no edges between all the vertices (use the analogy of a regular cube and figure out between which vertices of the cube there are edges).

This should preferably be done with Matlab.

Any help is appreciated!

This is as far as I've gotten:

vertices = [-1 -1 -1 -1; -1 -1 -1 1; -1 -1 1 -1; -1 -1 1 1;
-1 1 -1 -1; -1 1 -1 1; -1 1 1 -1; -1 1 1 1;
1 -1 -1 -1; 1 -1 -1 1; 1 -1 1 -1; 1 -1 1 1;
1 1 -1 -1; 1 1 -1 1; 1 1 1 -1; 1 1 1 1];

U = [2, 3, 4, 5];
B = [eye(4,3), U'];
D = diag([1,1,1,0]);
P = B*D/B;

projected_vertices = vertices * P';
disp(projected_vertices)

edges = [1 2; 1 3; 1 5; 2 4; 2 6; 3 4; 3 7; 4 8; 5 6; 5 7; 6 8; 7 8;
9 10; 9 11; 9 13; 10 12; 10 14; 11 12; 11 15; 12 16; 13 14; 13 15; 14 16; 15 16;
1 9; 2 10; 3 11; 4 12; 5 13; 6 14; 7 15; 8 16];

figure;

for i = 1:size(edges, 1)
    edge = edges(i, :);
    x = projected_vertices(edge, 1);
    y = projected_vertices(edge, 2);
    z = projected_vertices(edge, 3);
    plot3(x, y, z, 'b');
    hold on;
end

xlabel('X');
ylabel('Y');
zlabel('Z');
title('Projected hypercube');
grid on;
hold off;

enter image description here

1

There are 1 best solutions below

7
On BEST ANSWER

The fastest approach here is to use the matrix corresponding to the projection operator. To get that matrix, it is helpful to start by thinking of how this matrix should act on the basis $$ \mathcal B = \{e_1,e_2,e_3,u\}, $$ where $e_1,\dots,e_4$ denote the standard basis vectors (the columns of the identity matrix) and $u = (2,3,4,5)$. It is clear from the nature of the projection of interest that we should have $$ P(e_1) = e_1, \quad P(e_2) = e_2, \quad P(e_3) = e_3, \quad P(u) = 0. $$ To put it another way, $\mathcal B$ is an eigenbasis of the transformation with corresponding eigenvectors $1,1,1,0$. It follows that the matrix $P$ associated with this transformation should be of the form $P = BDB^{-1}$, where $$ D = \pmatrix{1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&0}, \quad B = \pmatrix{e_1 & e_2 & e_3 & u}. $$ With this matrix $P$ obtained, the projected vertices can be found with the command

projected_vertices = vertices * P';

Here's a script putting all of that together:

vertices = [-1 -1 -1 -1; -1 -1 -1 1; -1 -1 1 -1; -1 -1 1 1;
-1 1 -1 -1; -1 1 -1 1; -1 1 1 -1; -1 1 1 1;
1 -1 -1 -1; 1 -1 -1 1; 1 -1 1 -1; 1 -1 1 1;
1 1 -1 -1; 1 1 -1 1; 1 1 1 -1; 1 1 1 1];

U = [2, 3, 4, 5];
B = [eye(4,3), U'];
D = diag([1,1,1,0]);
P = B*D/B;

projected_vertices = vertices * P';

Code I used to generate a 3d plot:

edges = [1, 2; 1, 3; 1, 5; 1, 9; 2, 4; 2, 6; 2, 10; 3, 4; 
    3, 7; 3, 11; 4, 8; 4, 12; 5, 6; 5, 7; 5, 13; 6, 8; 
    6, 14; 7, 8; 7, 15; 8, 16; 9, 10; 9, 11; 9, 13; 10, 12; 
    10, 14; 11, 12; 11, 15; 12, 16; 13, 14; 13, 15; 14, 16; 15, 16];

scatter3(projected_vertices(:,1), ...
    projected_vertices(:,2), ...
    projected_vertices(:,3));
hold on 

for i = 1:32
    j = edges(i,1);
    k = edges(i,2);
    pts = projected_vertices([j,k],1:3);
    plot3(pts(:,1),pts(:,2),pts(:,3),'k');
end

xlabel('X')
ylabel('Y')

Result:

enter image description here


An alternative, quicker expression for $P$:

$$ P = I - \frac 15 u e_4^T $$