EliS
EliS

Reputation: 41

How to texture map to a rotated surface in matlab?

I would like to texture map a 2D image to a 3D surface. I would like to do it in GUI so the user can rotate/shift/zoom the surface with the camera toolbar and then the image will be mapped to the visible portion of the surface.

I know I can get the camera position with campos command, but how do I get the camera orientation?

Any idea? Or maybe you can suggest a better approach?

Thanks!

Upvotes: 2

Views: 898

Answers (1)

Benoit_11
Benoit_11

Reputation: 13945

To answer the question from your title (from what I understand), you can assign a texture map to 3D data using the accurately named texturemap value of the FaceColor property (original right?) as well as the appropriate CData (here a 2D image).

Simple example:

clear
clc

A = imread('peppers.png');

%// Generate dummy surface plot
[X,Y] = meshgrid([-2:.25:2]);
Z = X.*exp(-X.^2 -Y.^2);

surf(X,Y,Z,'CData',A,'FaceColor','texturemap')

It looks like this:

enter image description here

By default in a figure window you can zoom/move around as you want. For the 2nd part of your question, I think you should carefully read the docs for campos and related functions to get/set the camera position. Since building a GUI to perform that task requires much effort I think your best bet would be to try something on your own and ask questions about it here if you are stuck somewhere.

Hope that helps!

Upvotes: 3

Related Questions