Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: texture mapping images on the faces of a cube
Replies: 1   Last Post: Jan 31, 2013 6:46 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Ravi Posts: 10 Registered: 5/3/12
texture mapping images on the faces of a cube
Posted: Jan 30, 2013 10:47 AM
 Plain Text Reply

I am interested in mapping 6 different images on the faces of a cube. I found the following code from a previous posting on the newsgroup:

cdata = flipdim( imread('peppers.png'), 1 );
cdatar = flipdim( cdata, 2 );
% bottom
surface([-1 1; -1 1], [-1 -1; 1 1], [-1 -1; -1 -1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% top
surface([-1 1; -1 1], [-1 -1; 1 1], [1 1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
% front
surface([-1 1; -1 1], [-1 -1; -1 -1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
% back
surface([-1 1; -1 1], [1 1; 1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% left
surface([-1 -1; -1 -1], [-1 1; -1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% right
surface([1 1; 1 1], [-1 1; -1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
view(3);
%%%%%%%%%%%%%%%%
In order to adapt the above code in the right way (for example, to know when and how I should flip the image matrix), I would like to understand better the mapping method.
How do I read and understand the following code :
surface([-1 1; -1 1], [-1 -1; 1 1], [1 1; 1 1], ...
How does this represent the top? How should I understand the indexing of cube surface from the three 2*2 matrices?

I am actually interested in mapping images on a cuboid. How should the above code be modified then?
Would appreciate any help that I can get.
Thanks,
Ravi

Date Subject Author
1/30/13 Ravi
1/31/13 Ravi

© The Math Forum at NCTM 1994-2018. All Rights Reserved.