3-D Visualization

Texture Mapping

Texture mapping is a technique for mapping a 2-D image onto a 3-D surface by transforming color data so that it conforms to the surface plot. It allows you to apply a "texture," such as bumps or wood grain, to a surface without performing the geometric modeling necessary to create a surface with these features. The color data can also be any image, such as a scanned photograph.

Texture mapping allows the dimensions of the color data array to be different from the data defining the surface plot. You can apply an image of arbitrary size to any surface. MATLAB interpolates texture color data so that it is mapped to the entire surface.

Example - Texture Mapping a Surface

This example creates a spherical surface using the sphere function and texture maps it with an image of the earth taken from space. Because the earth image is a view of earth from one side, this example maps the image to only one side of the sphere, padding the image data with 1s. In this case, the image data is a 257-by-250 matrix so it is padded equally on each side with two 257-by-125 matrices of 1s by concatenating the three matrices together.

To use texture mapping, set the FaceColor to texturemap and assign the image to the surface's CData.

sphere; h = findobj('Type','surface');
hemisphere = [ones(257,125),...
X,...
ones(257,125)];
set(h,'CData',flipud(hemisphere),'FaceColor','texturemap')
colormap(map)
axis equal
view([90 0])
set(gca,'CameraViewAngleMode','manual')
view([65 30])

 Truecolor Surfaces Defining the View