Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
meshgrid with constant y

Subject: meshgrid with constant y

From: Jeff K

Date: 13 Jan, 2011 15:07:04

Message: 1 of 5

Hi,

I'm trying to plot an image to "a wall" in my 3d plot with surface -function.

How ever I'm unable to form the required meshgrid.

I'm trying to do:

[X Y Z] = meshgrid(1:10,0,1:10)

i.e. I have a wall that stands in the x-axis and is 10 units wide and 10 units tall.

now I try to use the surface function:

imag=imread('image.jpg');

surface(X,Y,Z,imag,'FaceColor','texturemap',EdgeColor,'none','CDataMapping','direct')

and I get an error that the dimensions must match and looking at X,Y and Z it is obvious that they are not what they are supposed to be to use the surface().

I tried

[X Y Z] = meshgrid(1:10,1:10,0)

and then used rotate to flip the plane 90 degrees. This worked in the sense that the image is upright but it's in the wrong position in terms of y-axis.

There must be a better way to do this.. If anyone can help, I'd appreciate it a lot!

Subject: meshgrid with constant y

From: Sean de

Date: 13 Jan, 2011 15:49:04

Message: 2 of 5

"Jeff K" wrote in message <ign4eo$p06$1@fred.mathworks.com>...
> Hi,
>
> I'm trying to plot an image to "a wall" in my 3d plot with surface -function.
>
> How ever I'm unable to form the required meshgrid.
>
> I'm trying to do:
>
> [X Y Z] = meshgrid(1:10,0,1:10)
>
> i.e. I have a wall that stands in the x-axis and is 10 units wide and 10 units tall.
>
> now I try to use the surface function:
>
> imag=imread('image.jpg');
>
> surface(X,Y,Z,imag,'FaceColor','texturemap',EdgeColor,'none','CDataMapping','direct')
>
> and I get an error that the dimensions must match and looking at X,Y and Z it is obvious that they are not what they are supposed to be to use the surface().
>
> I tried
>
> [X Y Z] = meshgrid(1:10,1:10,0)
>
> and then used rotate to flip the plane 90 degrees. This worked in the sense that the image is upright but it's in the wrong position in terms of y-axis.
>
> There must be a better way to do this.. If anyone can help, I'd appreciate it a lot!

Perhaps try using:
fill3
?

Subject: meshgrid with constant y

From: Jeff K

Date: 14 Jan, 2011 07:41:05

Message: 3 of 5

I tried to look more carefully into fill3 and patch but there's no mention of how to put a image on these things.

I have been able to first rotate the surface I created before and then manipulate the xDATA -property in case of each dimension to get it to the right position but this seems such a stupid way to do this...

Subject: meshgrid with constant y

From: Jeff K

Date: 14 Jan, 2011 08:04:04

Message: 4 of 5

To make things more complicated, I'd like the surfaces to face the camera when using rotate 3d. Just like in those old first person shooting games where the enemy always faces you. no matter which angle you are looking at them.

This far I'm thinking something like checking the camera angle each time the mouse button is released but then again this sounds complicated.

Now if I want my image to "stand" in the xy-plane in (10,20) for example I have:

%position
pos = [10 20];

%load image
im = imread('image.jpg');

%meshgrid
[X Y Z] = meshgrid(pos(1)-5:pos(1)+5, 0:10, 0);
%0:10 on ydata is the final height of the surface

%surface
img = surface(X,Y,Z,im,'FaceColor','texturemap','EdgeColor','none',CDataMapping','direct');

%rotation along x-axis
rotate(img,[1 0 0],90)

%manipulate xDatas
set(img,'YData',ones(size(get(img,'Ydata')))*pos(12))
%I want the zs to start from zero
set(img,'ZData',get(img,'Zdata')+abs(min(min(get(img,'Zdata')))))


This does the thing I want but looks awfully complicated. Also if I know change the zlim property the surface stretches and loses it proportions. It would be perfect if the surface would keep it's relative size too...

If someone has any ideas I'd be grateful!

Subject: meshgrid with constant y

From: Jeff K

Date: 14 Jan, 2011 08:34:05

Message: 5 of 5

btw, sorry for the typpos. I can't copypaste from my actual workstation...

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us