Assigning a 2D image for every face of a 3D cube: MATLAB -


i want build cube in matlab , assign different 2d images faces. think called texture mapping. i've searched such code, found code able assign single image of cube faces, code available here (http://www.mathworks.com/matlabcentral/answers/32070-rgb-images-on-a-3d-cube). here code,

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 );  % font surface([-1 1; -1 1], [-1 -1; -1 -1], [-1 -1; 1 1], ...     'facecolor', 'texturemap', 'cdata', cdata ); % 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); 

i want assign different pictures different faces, i've tried set different cdata variables cdata1, cdata2,..., cdata6 each has different image path, got error indicating cdata1 not defined.

edit: here i've tried using 2 images example,

cdata1 = flipdim( imread('face1.jpg'), 1 ); cdatar1 = flipdim( cdata1, 2 );  cdata2 = flipdim( imread('interface 1.png'), 1); cdatar2 = flipdim( cdata2, 2 );  % bottom surface([-1 1; -1 1], [-1 -1; 1 1], [-1 -1; -1 -1], ...     'facecolor', 'texturemap', 'cdata1', cdatar1 ); % top surface([-1 1; -1 1], [-1 -1; 1 1], [1 1; 1 1], ...     'facecolor', 'texturemap', 'cdata2', cdata2 );  % font surface([-1 1; -1 1], [-1 -1; -1 -1], [-1 -1; 1 1], ...     'facecolor', 'texturemap', 'cdata1', cdata1 ); % surface([-1 1; -1 1], [1 1; 1 1], [-1 -1; 1 1], ...     'facecolor', 'texturemap', 'cdata2', cdatar2 );  % left surface([-1 -1; -1 -1], [-1 1; -1 1], [-1 -1; 1 1], ...     'facecolor', 'texturemap', 'cdata1', cdatar2 ); % right surface([1 1; 1 1], [-1 1; -1 1], [-1 -1; 1 1], ...     'facecolor', 'texturemap', 'cdata1', cdata1 );  view(3); 

the code above yields error saying cdata1 not defined.

can tell me how above code capable of assigning different images different faces of cube?

thanks.

it should straightforward!

cdata1 = flipdim( imread('peppers.png'), 1 ); cdata2 = rgb2gray(flipdim( imread('peppers.png'), 1 )); 

it seems did not create variables correct name (cdata1, cdata2, cdata3 ,...)

additionally:

the name of property wan set in each of surface calls not change. want set cdata something. there no property in surface called cdata1 there no property called putimagehere ! replace calls 'cdata' in:

surface([1 1; 1 1], [-1 1; -1 1], [-1 -1; 1 1], ...     'facecolor', 'texturemap', 'cdata', yourvariablename);  % in case yourvariablename cdata1 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -