Creating a 3d diagram using multiple matrix
Mostrar comentarios más antiguos
I am trying to plot a rubiks cube, I currently have a 9x2 matrix with the coordinates of the peices. I have a seperate 9x3 matrix that has the color in RGB triplets.
I am trying to find a way to plot this, then eventually I would like to be able to watch it solve a cube.
I have this code here, which uses patch() to create a 3d cube, for some reason, only the top and bottom show up though.
axisLim=5;
figure
hold on
for p = 1:9; %White Face D
x = MwCoords(p,1);
y = MwCoords(p,2);
patch([x,x,x-1,x-1],[y-2,y-3,y-3,y-2],[0,0,0,0], MwC(p,:))
end
for p = 1:9; %Yellow Face U
x = MyCoords(p,1);
y = MyCoords(p,2);
patch([x,x,x-1,x-1],[y-2,y-3,y-3,y-2],[3,3,3,3], MyC(p,:))
end
for p = 1:9; %Orange Face F
y = MoCoords(p,1);
z = MoCoords(p,2);
patch([0,0,0,0],[y-3,y-3,y-2,y-2],[z,z,z,z], MoC(p,:))
end
for p = 1:9; %Red Face F
y = MrCoords(p,1);
z = MrCoords(p,2);
patch([3,3,3,3],[y-3,y-3,y-2,y-2],[z,z,z,z], MrC(p,:))
end
for p = 1:9; %Blue Face F
x = MbCoords(p,1);
y = MbCoords(p,2);
patch([x-1,x-1,x,x],[-2,-2,-2,-2],[y,y,y,y], MbC(p,:))
end
for p = 1:9; %Green Face F
x = MgCoords(p,1);
y = MgCoords(p,2);
patch([x-1,x-1,x,x],[1,1,1,1],[y,y,y,y], MgC(p,:))
end
hold off
You can just use this MwC for the colors, as an example
MwC =
1 1 1
1 0 1
0 1 0
0 0 1
1 1 1
1 0 0
1 0 0
1 0 0
1 1 0
Here are the all the coordinates
MwCoords =
1 3
1 2
1 1
2 1
2 2
2 3
3 1
3 2
3 3
MyCoords =
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 1
3 2
MoCoords =
1 3
1 2
1 1
2 1
2 2
2 3
3 1
3 3
3 2
MrCoords =
1 1
1 2
1 3
2 3
2 1
2 2
3 1
3 2
3 3
MbCoords =
1 3
1 2
1 1
2 3
2 2
2 1
3 2
3 3
3 1
MgCoords =
1 3
1 2
1 1
2 3
2 1
2 2
3 2
3 3
3 1
Sorry for this being a messy post, please let me know any ideas you may have
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




