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:
3D camera graphics with patches

Subject: 3D camera graphics with patches

From: Peter Bone

Date: 21 Oct, 2010 16:34:04

Message: 1 of 3

I'm trying to generate a 3D view from inside a box. The code is below. The camera position starts outside the Axes plot box and moves in until it's inside the box. It's fine until it gets inside the plot area and then it goes wrong. The example in the help files for the campos function does something similar but with the surf function instead of patches and it works fine. What's causing the problem and what can I do about it? I'm using 2008b.

w = 40; w2 = w/2;
l = 40; l2 = l/2;
h = 5;
patch([-w2 -w2 w2 w2], [-l2 l2 l2 -l2], [0 0 0 0], 'r')
patch([-w2 -w2 -w2 -w2], [-l2 l2 l2 -l2], [h h 0 0], 'g')
patch([w2 w2 w2 w2], [-l2 l2 l2 -l2], [h h 0 0], 'g')
patch([-w2 w2 w2 -w2], [l2 l2 l2 l2], [h h 0 0], 'g')
axis equal
axis vis3d off
camproj('perspective')
set(gca, 'CameraViewAngle', 90)
camtarget([0 100 5])

for i = -40 : 15
campos([0 i 5])
drawnow
pause(0.05)
end

Subject: 3D camera graphics with patches

From: Peter Bone

Date: 26 Oct, 2010 08:57:04

Message: 2 of 3

"Peter Bone" <peterbone@hotmail.com> wrote in message <i9pq1s$jf3$1@fred.mathworks.com>...
> I'm trying to generate a 3D view from inside a box. The code is below. The camera position starts outside the Axes plot box and moves in until it's inside the box. It's fine until it gets inside the plot area and then it goes wrong. The example in the help files for the campos function does something similar but with the surf function instead of patches and it works fine. What's causing the problem and what can I do about it? I'm using 2008b.
>
> w = 40; w2 = w/2;
> l = 40; l2 = l/2;
> h = 5;
> patch([-w2 -w2 w2 w2], [-l2 l2 l2 -l2], [0 0 0 0], 'r')
> patch([-w2 -w2 -w2 -w2], [-l2 l2 l2 -l2], [h h 0 0], 'g')
> patch([w2 w2 w2 w2], [-l2 l2 l2 -l2], [h h 0 0], 'g')
> patch([-w2 w2 w2 -w2], [l2 l2 l2 l2], [h h 0 0], 'g')
> axis equal
> axis vis3d off
> camproj('perspective')
> set(gca, 'CameraViewAngle', 90)
> camtarget([0 100 5])
>
> for i = -40 : 15
> campos([0 i 5])
> drawnow
> pause(0.05)
> end

Sorry to bump this but I'm still having a problem with this. Could someone at least try running the above code on a recent version of Matlab to see if you get the same problem? The problem is obvious. The back wall seems to disappear and then some other patches appear where they shouldn't be.

Subject: 3D camera graphics with patches

From: Peter Bone

Date: 26 Oct, 2010 15:54:03

Message: 3 of 3

I've now replaced the patches with texture mapped surf surfaces and it seems to work much better. The only problem is now that the front and back walls are invisible when looking straight at them. Does anyone know why that would be?

Tags for 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