Easy way to set camera viewing axis normal to a plane

264 Ansichten (letzte 30 Tage)
Jason
Jason am 2 Jul. 2011
Kommentiert: Timothy Russell am 29 Sep. 2021
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.

Antworten (3)

Matt Fig
Matt Fig am 2 Jul. 2011
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 Kommentare
Jason
Jason am 8 Jul. 2011
Thanks for the quick response and help.
Timothy Russell
Timothy Russell am 29 Sep. 2021
how do you rotate the YZ view 90 degrees?

Melden Sie sich an, um zu kommentieren.


Paulo Silva
Paulo Silva am 2 Jul. 2011
doc view

Massimo Ciacci
Massimo Ciacci am 2 Mai 2016
Bearbeitet: Massimo Ciacci am 2 Mai 2016
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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by