Easy way to set camera viewing axis normal to a plane

66 vues (au cours des 30 derniers jours)
Jason
Jason le 2 Juil 2011
Commenté : Timothy Russell le 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.

Réponses (3)

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

Connectez-vous pour commenter.


Paulo Silva
Paulo Silva le 2 Juil 2011

Massimo Ciacci
Massimo Ciacci le 2 Mai 2016
Modifié(e) : Massimo Ciacci le 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

Catégories

En savoir plus sur MATLAB Support Package for USB Webcams dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by