1.\" Copyright (c) 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)atan2.3 5.1 (Berkeley) 5/2/91
| 1.\" Copyright (c) 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)atan2.3 5.1 (Berkeley) 5/2/91
|
33.\" $Id: atan2.3,v 1.3 1993/08/14 13:42:32 mycroft Exp $
| 33.\" $Id: atan2.3,v 1.1.1.1 1994/08/19 09:39:41 jkh Exp $
|
34.\" 35.Dd May 2, 1991 36.Dt ATAN2 3 37.Os 38.Sh NAME
| 34.\" 35.Dd May 2, 1991 36.Dt ATAN2 3 37.Os 38.Sh NAME
|
39.Nm atan2 40.Nd arc tangent function of two variables
| 39.Nm atan2 , 40.Nm atan2f 41.Nd arc tangent functions of two variables
|
41.Sh SYNOPSIS 42.Fd #include <math.h> 43.Ft double 44.Fn atan2 "double y" "double x"
| 42.Sh SYNOPSIS 43.Fd #include <math.h> 44.Ft double 45.Fn atan2 "double y" "double x"
|
| 46.Ft float 47.Fn atan2f "float y" "float x"
|
45.Sh DESCRIPTION 46The
| 48.Sh DESCRIPTION 49The
|
47.Xr atan2 48function computes the principal value of the arc tangent of 49.Ar y/ Ns Ar x ,
| 50.Fn atan2 51and the 52.Fn atan2f 53functions compute the principal value of the arc tangent of 54.Fa y/ Ns Ar x ,
|
50using the signs of both arguments to determine the quadrant of 51the return value. 52.Sh RETURN VALUES 53The
| 55using the signs of both arguments to determine the quadrant of 56the return value. 57.Sh RETURN VALUES 58The
|
54.Xr atan2 55function, if successful, 56returns the arc tangent of 57.Ar y/ Ns Ar x
| 59.Fn atan2 60and the 61.Fn atan2f 62functions, if successful, 63return the arc tangent of 64.Fa y/ Ns Ar x
|
58in the range 59.Bk -words 60.Bq \&- Ns \*(Pi , \&+ Ns \*(Pi 61.Ek 62radians. 63If both
| 65in the range 66.Bk -words 67.Bq \&- Ns \*(Pi , \&+ Ns \*(Pi 68.Ek 69radians. 70If both
|
64.Ar x
| 71.Fa x
|
65and
| 72and
|
66.Ar y
| 73.Fa y
|
67are zero, the global variable 68.Va errno 69is set to 70.Er EDOM . 71On the 72.Tn VAX : 73.Bl -column atan_(y,x)_:=____ sign(y)_(Pi_atan2(Xy_xX))___ 74.It Fn atan2 y x No := Ta 75.Fn atan y/x Ta 76if 77.Ar x 78> 0, 79.It Ta sign( Ns Ar y Ns )*(\*(Pi - 80.Fn atan "\\*(Bay/x\\*(Ba" ) Ta 81if 82.Ar x 83< 0, 84.It Ta 85.No 0 Ta 86if x = y = 0, or 87.It Ta 88.Pf sign( Ar y Ns )*\\*(Pi/2 Ta 89if 90.Ar x 91= 0 \*(!= 92.Ar y . 93.El 94.Sh NOTES 95The function 96.Fn atan2 97defines "if x > 0," 98.Fn atan2 0 0 99= 0 on a 100.Tn VAX 101despite that previously 102.Fn atan2 0 0 103may have generated an error message. 104The reasons for assigning a value to 105.Fn atan2 0 0 106are these: 107.Bl -enum -offset indent 108.It 109Programs that test arguments to avoid computing 110.Fn atan2 0 0 111must be indifferent to its value. 112Programs that require it to be invalid are vulnerable 113to diverse reactions to that invalidity on diverse computer systems. 114.It 115The 116.Fn atan2 117function is used mostly to convert from rectangular (x,y) 118to polar 119.if n\ 120(r,theta) 121.if t\ 122(r,\(*h) 123coordinates that must satisfy x = 124.if n\ 125r\(**cos theta 126.if t\ 127r\(**cos\(*h 128and y = 129.if n\ 130r\(**sin theta. 131.if t\ 132r\(**sin\(*h. 133These equations are satisfied when (x=0,y=0) 134is mapped to 135.if n \ 136(r=0,theta=0) 137.if t \ 138(r=0,\(*h=0) 139on a VAX. In general, conversions to polar coordinates 140should be computed thus: 141.Bd -unfilled -offset indent 142.if n \{\ 143r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) 144theta := atan2(y,x). 145.\} 146.if t \{\ 147r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) 148\(*h := atan2(y,x). 149.\} 150.Ed 151.It 152The foregoing formulas need not be altered to cope in a 153reasonable way with signed zeros and infinities 154on a machine that conforms to 155.Tn IEEE 754 ; 156the versions of 157.Xr hypot 3 158and 159.Fn atan2 160provided for 161such a machine are designed to handle all cases. 162That is why 163.Fn atan2 \(+-0 \-0 164= \(+-\*(Pi 165for instance. 166In general the formulas above are equivalent to these: 167.Bd -unfilled -offset indent 168.if n \ 169r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); 170.if t \ 171r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); 172.Ed 173.El 174.Sh SEE ALSO 175.Xr acos 3 , 176.Xr asin 3 , 177.Xr atan 3 , 178.Xr cos 3 , 179.Xr cosh 3 , 180.Xr sin 3 , 181.Xr sinh 3 , 182.Xr tan 3 , 183.Xr tanh 3 , 184.Xr math 3 , 185.Sh STANDARDS 186The 187.Fn atan2 188function conforms to 189.St -ansiC .
| 74are zero, the global variable 75.Va errno 76is set to 77.Er EDOM . 78On the 79.Tn VAX : 80.Bl -column atan_(y,x)_:=____ sign(y)_(Pi_atan2(Xy_xX))___ 81.It Fn atan2 y x No := Ta 82.Fn atan y/x Ta 83if 84.Ar x 85> 0, 86.It Ta sign( Ns Ar y Ns )*(\*(Pi - 87.Fn atan "\\*(Bay/x\\*(Ba" ) Ta 88if 89.Ar x 90< 0, 91.It Ta 92.No 0 Ta 93if x = y = 0, or 94.It Ta 95.Pf sign( Ar y Ns )*\\*(Pi/2 Ta 96if 97.Ar x 98= 0 \*(!= 99.Ar y . 100.El 101.Sh NOTES 102The function 103.Fn atan2 104defines "if x > 0," 105.Fn atan2 0 0 106= 0 on a 107.Tn VAX 108despite that previously 109.Fn atan2 0 0 110may have generated an error message. 111The reasons for assigning a value to 112.Fn atan2 0 0 113are these: 114.Bl -enum -offset indent 115.It 116Programs that test arguments to avoid computing 117.Fn atan2 0 0 118must be indifferent to its value. 119Programs that require it to be invalid are vulnerable 120to diverse reactions to that invalidity on diverse computer systems. 121.It 122The 123.Fn atan2 124function is used mostly to convert from rectangular (x,y) 125to polar 126.if n\ 127(r,theta) 128.if t\ 129(r,\(*h) 130coordinates that must satisfy x = 131.if n\ 132r\(**cos theta 133.if t\ 134r\(**cos\(*h 135and y = 136.if n\ 137r\(**sin theta. 138.if t\ 139r\(**sin\(*h. 140These equations are satisfied when (x=0,y=0) 141is mapped to 142.if n \ 143(r=0,theta=0) 144.if t \ 145(r=0,\(*h=0) 146on a VAX. In general, conversions to polar coordinates 147should be computed thus: 148.Bd -unfilled -offset indent 149.if n \{\ 150r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) 151theta := atan2(y,x). 152.\} 153.if t \{\ 154r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) 155\(*h := atan2(y,x). 156.\} 157.Ed 158.It 159The foregoing formulas need not be altered to cope in a 160reasonable way with signed zeros and infinities 161on a machine that conforms to 162.Tn IEEE 754 ; 163the versions of 164.Xr hypot 3 165and 166.Fn atan2 167provided for 168such a machine are designed to handle all cases. 169That is why 170.Fn atan2 \(+-0 \-0 171= \(+-\*(Pi 172for instance. 173In general the formulas above are equivalent to these: 174.Bd -unfilled -offset indent 175.if n \ 176r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); 177.if t \ 178r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); 179.Ed 180.El 181.Sh SEE ALSO 182.Xr acos 3 , 183.Xr asin 3 , 184.Xr atan 3 , 185.Xr cos 3 , 186.Xr cosh 3 , 187.Xr sin 3 , 188.Xr sinh 3 , 189.Xr tan 3 , 190.Xr tanh 3 , 191.Xr math 3 , 192.Sh STANDARDS 193The 194.Fn atan2 195function conforms to 196.St -ansiC .
|