Easy way to set camera viewing axis normal to a plane

조회 수: 216 (최근 30일)
Jason
Jason 2011년 7월 2일
댓글: Timothy Russell 2021년 9월 29일
Is there an easy way to set the camera viewing axis normal to one of the planes in a 3D plot. That is set the camera to only look at the xy plane or xz plane, etc. Trying to position the camera manually does not work well and is very frustrating.
I created a bunch of .fig files of some data points in 3D space and now I am trying to visualize them from different angles, namely looking down(xy plane) and across(xz-yz planes).
Thanks for the help.

답변 (3개)

Matt Fig
Matt Fig 2011년 7월 2일
Run this to see. Look at the view of the plot that pops up, then press return to see the next view. Do this twice.
plot3(0,0,0)
axis([-1 1 -1 1 -1 1])
xlabel('X')
ylabel('Y')
zlabel('Z')
view(0,90) % XY
pause
view(0,0) % XZ
pause
view(90,0) % YZ
  댓글 수: 2
Jason
Jason 2011년 7월 8일
Thanks for the quick response and help.
Timothy Russell
Timothy Russell 2021년 9월 29일
how do you rotate the YZ view 90 degrees?

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


Paulo Silva
Paulo Silva 2011년 7월 2일

Massimo Ciacci
Massimo Ciacci 2016년 5월 2일
편집: Massimo Ciacci 2016년 5월 2일
I guess the following function should do, it is based on the fact that the conversion [x,y,z] to [az,el] to [x,y,z] is
x=sin(az)*cos(el)
y=cos(az)*cos(el)
z=sin(el)
and therefore
az = 180/pi*asin(x/sqrt(x^2+y^2));
el = 180/pi*asin(z);
---------------
function [az,el]=normalToAzimuthElevationDEG(x,y,z, applyView)
if nargin < 3
applyView = 0;
end
if length(x)>1
v = x;
if nargin > 1
applyView = y;
end
x=v(1);
y=v(2);
z=v(3);
end
if x==0 && y==0
x =eps;
end
vNorm = sqrt(x^2+y^2+z^2);
x=x/vNorm;
y=y/vNorm;
z=z/vNorm;
az = 180/pi*asin(x/sqrt(x^2+y^2));
el = 180/pi*asin(z);
if applyView
thereIsAnOpenFig = ~isempty(findall(0,'Type','Figure'));
if thereIsAnOpenFig
axis equal
view([az,el]);
%the normal to the plane should now appear as a point
plot3([0,x],[0,y],[0,z],'linewidth',3)
end
end

카테고리

Help CenterFile Exchange에서 Camera Views에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by