Easy way to set camera viewing axis normal to a plane

217 次查看(过去 30 天)
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

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