Special 3D Plotting
Show older comments
Hi. Imagine I have a hypothetical Rubix cube with arbitrary numbers of inner cubes.
The co-ordinates of the center points of its inner cubes are saved in the matrix A, e.g.
A =[2 2 2 1
3 2 2 2
4 2 2 3
2 3 2 2
3 3 2 3
4 3 2 2
2 4 2 2
3 4 2 1
4 4 2 3
2 2 3 1
3 2 3 1
4 2 3 2
2 3 3 3
3 3 3 2
4 3 3 1
2 4 3 2
3 4 3 3
4 4 3 3
2 2 4 1
3 2 4 2
4 2 4 1
2 3 4 3
3 3 4 2
4 3 4 3
2 4 4 3
3 4 4 2
4 4 4 1];
In the matrix A, the first column are X co-ordinates, the second column are Y co-ordinates and the third column are Z co-ordinates of the center points of the inner cubes and every row demonstrates an inner cube.
Also every inner cube have a value in the forth column of matrix A.
I want to 3D plot this rubix cube and I want to show the corresponding values in the forth column of matrix A on corresponding cubes.
Also I want to colorize the cubes based on their corresponding values in the forth column of matrix A.
For example I want to colorize the cubes with values of 1 in red color, the cubes with values of 2 in blue color and the cubes with values of 3 in green color.
Also I want to have a legend based on these colors.
How can I do that? Thanks a lot.
9 Comments
Rik
on 18 Nov 2017
You can use patch to draw polygons in 3D of a specified color. If you save the handles in an array, you can use it with in a call to legend.
Rik
on 19 Nov 2017
Have your read the documentation for patch? If you don't show you're trying, this is just a doit4me.
Showing text on a face is a bit harder. You could try to hack something together with generating an image with a number hard-coded, and then using that as the CData. But it is much easier to use the text function to plot the number as text objects in 3D space.
mr mo
on 19 Nov 2017
Rik
on 19 Nov 2017
You need to find the vertices for each face you want to draw. You already have the center coordinates, so it shouldn't be hard to find the corner coordinates. Once you have all coordinates, get a unique list of them and create a matrix that contains the indices to the vertices. Each row is one face.
I'm not going to give you code, but I will help you correct non-working code.
mr mo
on 19 Nov 2017
Rik
on 19 Nov 2017
I they have faces in common that doesn't matter, because you will not be able to see them anyway. Get a working solution first, and then try to think about a way to eliminate the unused faces.
There is only one advice I can give you: write code. If you don't write code, no-one can help you. The only thing people could do is doing your job for you, which is not what this forum is for.
mr mo
on 19 Nov 2017
Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!