How to make MATLAB render 3D objects properly on close up?

13 visualizaciones (últimos 30 días)
Mingjing Zhang
Mingjing Zhang el 8 de Feb. de 2012
Okay I know this question might be weird. Normally we would view a 3D object (e.g. the surface object created with surf()) from a distance away. However, for some reason, I need to move the camera really close to the objects, for example, in between two parallel flat surfaces which are not too far apart from each other. However, whenever I do that, the object just "disappeared". They would only reappear when I move the camera further from the surfaces. I am not sure if there is any workaround to this problem. If you do have an answer, please let me know. --- Update: Sorry for not being clear. Here is one example: I created two parallel surfaces, and I hope to visualize the two surfaces from between them as if I stand between two "walls". Here is the code:
[x z] = meshgrid(0:20);
y = zeros(size(x));
surf(x,y,z);
xlabel('x');
hold on;
surf(x, y+1,z);
set(gca,'YLim',[-2 2]);
shading flat;
camproj perspective;
campos([5 0.5 50]);
camtarget([15 0.5 10]);
This segment of code gives me a correct bird-view. However, what I really want is to place the camera at [5 0.5 10]. if I lower the camera by changing the second last line to
campos([5 0.5 20])
I see nothing except for a deformed axes. If I further lower the camera to [5 0.5 10], I see nothing at all, not even the axes itself.

Respuestas (2)

Jan
Jan el 8 de Feb. de 2012
Objects behind the camera plane are not drawn. Try to change the view-angle instead of the camera position. Then it looks like you get nearer, but without the drawbacks of disappearing objects.

Patrick Kalita
Patrick Kalita el 8 de Feb. de 2012
Ah, okay. Here's what's going on. There are three axes camera properties that you need to worry about. You are currently only setting two of them. Specifically, you are setting the CameraPosition (via campos) and CameraTarget (via camtarget). However, there is a third, property, CameraViewAngle, that is also important.
If you set CameraPosition and CameraTarget without setting the CameraViewAngle, MATLAB will automatically try to adjust the CameraViewAngle for you, with the goal of keeping the entire scene in view. That is described in the fourth row of this table.
But in your case, you are setting the camera's position to be between two objects. Therefore when MATLAB tries to automatically come up with CameraViewAngle that keeps everything visible, it comes up with kind of a crazy value (because no matter what the view angle is, it won't be able to see everything in the scene from its position).
The solution, therefore, it to just set the CameraViewAngle to some value before moving the camera to between the two objects:
[x z] = meshgrid(0:20);
y = zeros(size(x));
surf(x,y,z);
xlabel('x');
hold on;
surf(x, y+1,z);
set(gca,'YLim',[-2 2]);
shading flat;
camproj perspective;
campos([5 0.5 50]);
camtarget([15 0.5 10]);
% Set a nice CameraViewAngle here so that MATLAB doesn't
% try to adjust it when we move the camera. 45 isn't a
% particularly special number, you can experiment with this.
camva(45);
Now when you move the camera you should get the desired results:
campos([5 0.5 20])
Here are some documentation pages for further reference:

Categorías

Más información sobre Camera Views en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by