Setting camera properties on axes is not working as I'm expecting

조회 수: 2 (최근 30일)
Axel
Axel 2011년 11월 9일
Hi,
I'm trying to display a model consisting of many planes. I'm using 'surf' to draw these planes. Similar to this:
for k = 1:100
X_k = X(K); % Similar for other vars
hold on; surf(X_k,Y_k,Z_k,C_k,'FaceColor','texturemap','EdgeColor','none');
hold off;
end
After the loop I try to set the axes camera properties, simlar to this:
set(gca,'CameraPosition', center(1:3), 'CameraPositionMode', 'manual', ...
'CameraTarget', target(1:3), 'CameraTargetMode', 'manual', ...
'CameraUpVector', up(1:3), 'CameraUpVectorMode', 'manual', ...
'CameraViewAngle', viewangle, 'CameraViewAngleMode', 'manual');
drawnow;
If I get the parameters from the axes again, by using get(gca, ... I don't get the same value as I just have set.
Why is that? Is something being automatically calculated for me? What I notice is, that camera position and target has changed.

채택된 답변

Axel
Axel 2011년 11월 9일
I think the problem has to do with the axes limits or data aspect ratio to do. Fixing those seems to solve the problem.
@Daniel: Thank you for your input. It helped a lot.

추가 답변 (1개)

Daniel Shub
Daniel Shub 2011년 11월 9일
This seems to work for me
[x, y, z] = peaks;
mesh(x, y, z)
hold on
set(gca,'CameraPosition', center(1:3), 'CameraPositionMode', 'manual', ...
'CameraTarget', target(1:3), 'CameraTargetMode', 'manual', ...
'CameraUpVector', up(1:3), 'CameraUpVectorMode', 'manual', ...
'CameraViewAngle', viewangle, 'CameraViewAngleMode', 'manual');
all([isequal(get(gca,'CameraPosition'), center)
isequal(get(gca,'CameraTarget'), target)
isequal(get(gca,'CameraUpVector'), up)
isequal(get(gca,'CameraViewAngle'), viewangle)])
for ii = 1:10
mesh(x, y, z+10*ii);
all([isequal(get(gca,'CameraPosition'), center)
isequal(get(gca,'CameraTarget'), target)
isequal(get(gca,'CameraUpVector'), up)
isequal(get(gca,'CameraViewAngle'), viewangle)])
end
What are you expecting to get and what are you getting?
  댓글 수: 2
Axel
Axel 2011년 11월 9일
Hi Daniel. I tried your example and did a bit more debugging. It is still not acting like I am expecting. When I plot my surface, I assume, that later plots of other surfaces on the same axes will not change the view of the first plottet surface, but it does. Maybe it is not the camera, that is changed, but something else.
I have to look a bit more at this.
What I am trying to do, which is slightly different from your example, is keeping the camera parameters fixed, iteratively plot new sufaces on an existing axes.
I might have a model of a building, and the surfaces are the different sides and the roof of the building. If I start by plotting the roof, it needs to be at the top of the axes, not in the center. And when I plot the other surfaces, the roof surface will not move (or the view will not change).
Daniel Shub
Daniel Shub 2011년 11월 9일
See my edited code which now plots new surfaces/meshes in a loop. The camera angle seems to stay constant.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by