function [ret1, ret2] = view(arg1, arg2)
% VIEW	3-D graph viewpoint specification. 
% 	VIEW(AZ,EL) and VIEW([AZ,EL]) set the angle of the view from which an
%	observer sees the current 3-D plot.  AZ is the azimuth or horizontal 
%	rotation and EL is the vertical elevation (both in degrees). Azimuth 
%	revolves about the z-axis, with positive values indicating counter-
%	clockwise rotation of the viewpoint. Positive values of elevation 
%	correspond to moving above the object; negative values move below.
%	VIEW([X Y Z]) sets the view angle in cartesian coordinates. The
%	magnitude of vector X,Y,Z is ignored.
% 
% 	Here are some examples:
% 
% 	AZ = -37.5, EL = 30 is the default 3-D view.
% 	AZ = 0, EL = 90 is directly overhead and the default 2-D view.
% 	AZ = EL = 0 looks directly up the first column of the matrix.
% 	AZ = 180 is behind the matrix.
%
%	VIEW(2) sets the default 2-D view, AZ = 0, EL = 90.
%	VIEW(3) sets the default 3-D view, AZ = -37.5, EL = 30.
%
% 	[AZ,EL] = VIEW returns the current azimuth and elevation.
% 
% 	VIEW(T) accepts a 4-by-4 transformation matrix, such as 
% 	the perspective transformations generated by VIEWMTX.
%
% 	T = VIEW returns the current general 4-by-4 transformation matrix.
%
%	See also VIEWMTX, the AXES properties View, Xform.

%	Copyright (c) 1984-93 by The MathWorks, Inc.

fig = gcf;
ax = gca;
err = 0;
if (nargin == 0)
	if(nargout < 2)
		ret1 = get(ax,'xform');
	else
		v = get(ax,'View');
		ret1  = v(1); ret2 = v(2);
	end
elseif (nargin == 1)
	[r,c] = size(arg1);
	if (r == 1) & (c == 2)
		set(ax,'View',arg1);
	elseif ((r==1) & (c == 1))
		if arg1 == 2
			view(0,90);
		elseif arg1 == 3 
			view(-37.5,30);
		else
			error('Single scalar argument must be 2 or 3');
		end
	elseif ((r == 4) & (c == 4))
		set(ax,'xform',arg1);
	elseif r*c == 3	% it's a direction vector
		unit = arg1/norm(arg1);
		az = atan2(unit(2),unit(1))*180/pi;
		el = atan2(unit(3),sqrt(unit(1)^2+unit(2)^2))*180/pi;
		set(ax,'View',[az el]);
	else
		error('Argument must be scalar, two-vector, or 4-by-4 matrix');
	end
else
	[r,c] = size(arg1);
	[r2,c2] = size(arg2);
	if ((r == 1) & (c == 1) & (r2 == 1) & (c2 == 1))
		set(ax,'View',[arg1 arg2]);
	else
		error('Arguments must be scalars');
	end
end

