sa=spaceangle(az1,el1,az2,el2,units) Calculate the space angle between vectors az1,el1 and az2,el2 If optional parameter units is 'deg' inputs and outputs in degrees. Otherwise radians
0001 function sa=spaceangle(az1,el1,az2,el2,units) 0002 % sa=spaceangle(az1,el1,az2,el2,units) 0003 % 0004 % Calculate the space angle between vectors az1,el1 and az2,el2 0005 % 0006 % If optional parameter units is 'deg' inputs and outputs in 0007 % degrees. Otherwise radians 0008 0009 if(~exist('units')) 0010 units='rad'; 0011 end 0012 0013 if(strcmp(units,'deg')) 0014 d2r=pi/180; 0015 az1=az1*d2r; az2=az2*d2r; 0016 el1=el1*d2r; el2=el2*d2r; 0017 end 0018 0019 [x1,y1,z1]=sph2cart(az1,el1,1); 0020 [x2,y2,z2]=sph2cart(az2,el2,1); 0021 0022 sa=acos(x1.*x2+y1.*y2+z1.*z2); 0023 0024 if(strcmp(units,'deg')) 0025 sa=sa/d2r; 0026 end 0027 0028 0029 0030 0031