Home > voicebox > atan2sc.m

# atan2sc

## PURPOSE

ATAN2SC sin and cosine of atan(y/x) [S,C,R,T]=(Y,X)

## SYNOPSIS

function [s,c,r,t]=atan2sc(y,x)

## DESCRIPTION

```ATAN2SC    sin and cosine of atan(y/x) [S,C,R,T]=(Y,X)

Outputs:
s    sin(t) where tan(t) = y/x
C    cos(t) where tan(t) = y/x
r    sqrt(x^2 + y^2)
t    arctan of y/x```

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:
• rotpl2ro ROTPL2RO find matrix to rotate in the plane containing u and v r=[u,v,t]
• rotqr2eu ROTQR2EQ converts a real unit quaternion into the corresponding euler angles
• rotro2eu ROTRO2EQ converts a 3x3 rotation matrix into the corresponding euler angles
• rotro2pl ROTRO2PL find the plane and rotation angle of a rotation matrix [u,v,t]=r

## SOURCE CODE

```0001 function [s,c,r,t]=atan2sc(y,x)
0002 %ATAN2SC    sin and cosine of atan(y/x) [S,C,R,T]=(Y,X)
0003 %
0004 % Outputs:
0005 %    s    sin(t) where tan(t) = y/x
0006 %    C    cos(t) where tan(t) = y/x
0007 %    r    sqrt(x^2 + y^2)
0008 %    t    arctan of y/x
0009
0010 %      Copyright (C) Mike Brookes 2007
0011 %      Version: \$Id: atan2sc.m 713 2011-10-16 14:45:43Z dmb \$
0012 %
0013 %   VOICEBOX is a MATLAB toolbox for speech processing.
0015 %
0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0017 %   This program is free software; you can redistribute it and/or modify
0019 %   the Free Software Foundation; either version 2 of the License, or
0020 %   (at your option) any later version.
0021 %
0022 %   This program is distributed in the hope that it will be useful,
0023 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0025 %   GNU General Public License for more details.
0026 %
0027 %   You can obtain a copy of the GNU General Public License from
0028 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0029 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0031
0032
0033 t=NaN;
0034 if y == 0
0035     t=(x<0);
0036     c=1-2*t;
0037     s=0;
0038     r=abs(x);
0039     t=t*pi;
0040 elseif x == 0
0041     s=2*(y>=0)-1;
0042     c=0;
0043     r=abs(y);
0044     t=s*0.5*pi;
0045 elseif (abs(y) > abs(x))
0046     q = x/y;
0047     u = sqrt(1+q^2)*(2*(y>=0)-1);
0048     s = 1/u;
0049     c = s*q;
0050     r = y*u;
0051 else
0052     q = y/x;
0053     u = sqrt(1+q^2)*(2*(x>=0)-1);
0054     c = 1/u;
0055     s = c*q;
0056     r = x*u;
0057 end
0058 if nargout>3 && isnan(t)
0059     t=atan2(s,c);
0060 end```

Generated on Mon 06-Aug-2018 14:48:32 by m2html © 2003