The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | .\" $FreeBSD: src/lib/msun/man/atan2.3,v 1.14 2005/01/28 21:13:34 ru Exp $ |
| 34 | .\" |
| 35 | .Dd January 14, 2005 |
| 36 | .Dt ATAN2 3 |
| 37 | .Os |
| 38 | .Sh NAME |
| 39 | .Nm atan2 , |
| 40 | .Nm atan2f |
| 41 | .Nd arc tangent functions of two variables |
| 42 | .Sh LIBRARY |
| 43 | .Lb libm |
| 44 | .Sh SYNOPSIS |
| 45 | .In math.h |
| 46 | .Ft double |
| 47 | .Fn atan2 "double y" "double x" |
| 48 | .Ft float |
| 49 | .Fn atan2f "float y" "float x" |
| 50 | .Sh DESCRIPTION |
| 51 | The |
| 52 | .Fn atan2 |
| 53 | and the |
| 54 | .Fn atan2f |
| 55 | functions compute the principal value of the arc tangent of |
| 56 | .Fa y/ Ns Ar x , |
| 57 | using the signs of both arguments to determine the quadrant of |
| 58 | the return value. |
| 59 | .Sh RETURN VALUES |
| 60 | The |
| 61 | .Fn atan2 |
| 62 | and the |
| 63 | .Fn atan2f |
| 64 | functions, if successful, |
| 65 | return the arc tangent of |
| 66 | .Fa y/ Ns Ar x |
| 67 | in the range |
| 68 | .Bk -words |
| 69 | .Bq \&- Ns \*(Pi , \&+ Ns \*(Pi |
| 70 | .Ek |
| 71 | radians. |
| 72 | Here are some of the special cases: |
| 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 |
| 76 | if |
| 77 | .Ar x |
| 78 | > 0, |
| 79 | .It Ta sign( Ns Ar y Ns )*(\*(Pi - |
| 80 | .Fn atan "\\*(Bay/x\\*(Ba" ) Ta |
| 81 | if |
| 82 | .Ar x |
| 83 | < 0, |
| 84 | .It Ta |
| 85 | .No 0 Ta |
| 86 | if x = y = 0, or |
| 87 | .It Ta |
| 88 | .Pf sign( Ar y Ns )*\\*(Pi/2 Ta |
| 89 | if |
| 90 | .Ar x |
| 91 | = 0 \(!= |
| 92 | .Ar y . |
| 93 | .El |
| 94 | .Sh NOTES |
| 95 | The function |
| 96 | .Fn atan2 |
| 97 | defines "if x > 0," |
| 98 | .Fn atan2 0 0 |
| 99 | = 0 despite that previously |
| 100 | .Fn atan2 0 0 |
| 101 | may have generated an error message. |
| 102 | The reasons for assigning a value to |
| 103 | .Fn atan2 0 0 |
| 104 | are these: |
| 105 | .Bl -enum -offset indent |
| 106 | .It |
| 107 | Programs that test arguments to avoid computing |
| 108 | .Fn atan2 0 0 |
| 109 | must be indifferent to its value. |
| 110 | Programs that require it to be invalid are vulnerable |
| 111 | to diverse reactions to that invalidity on diverse computer systems. |
| 112 | .It |
| 113 | The |
| 114 | .Fn atan2 |
| 115 | function is used mostly to convert from rectangular (x,y) |
| 116 | to polar |
| 117 | .if n\ |
| 118 | (r,theta) |
| 119 | .if t\ |
| 120 | (r,\(*h) |
| 121 | coordinates that must satisfy x = |
| 122 | .if n\ |
| 123 | r\(**cos theta |
| 124 | .if t\ |
| 125 | r\(**cos\(*h |
| 126 | and y = |
| 127 | .if n\ |
| 128 | r\(**sin theta. |
| 129 | .if t\ |
| 130 | r\(**sin\(*h. |
| 131 | These equations are satisfied when (x=0,y=0) |
| 132 | is mapped to |
| 133 | .if n \ |
| 134 | (r=0,theta=0). |
| 135 | .if t \ |
| 136 | (r=0,\(*h=0). |
| 137 | In general, conversions to polar coordinates |
| 138 | should be computed thus: |
| 139 | .Bd -unfilled -offset indent |
| 140 | .if n \{\ |
| 141 | r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) |
| 142 | theta := atan2(y,x). |
| 143 | .\} |
| 144 | .if t \{\ |
| 145 | r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) |
| 146 | \(*h := atan2(y,x). |
| 147 | .\} |
| 148 | .Ed |
| 149 | .It |
| 150 | The foregoing formulas need not be altered to cope in a |
| 151 | reasonable way with signed zeros and infinities |
| 152 | on a machine that conforms to |
| 153 | .Tn IEEE 754 ; |
| 154 | the versions of |
| 155 | .Xr hypot 3 |
| 156 | and |
| 157 | .Fn atan2 |
| 158 | provided for |
| 159 | such a machine are designed to handle all cases. |
| 160 | That is why |
| 161 | .Fn atan2 \(+-0 \-0 |
| 162 | = \(+-\*(Pi |
| 163 | for instance. |
| 164 | In general the formulas above are equivalent to these: |
| 165 | .Bd -unfilled -offset indent |
| 166 | .if n \ |
| 167 | r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); |
| 168 | .if t \ |
| 169 | r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); |
| 170 | .Ed |
| 171 | .El |
| 172 | .Sh SEE ALSO |
| 173 | .Xr acos 3 , |
| 174 | .Xr asin 3 , |
| 175 | .Xr atan 3 , |
| 176 | .Xr cos 3 , |
| 177 | .Xr cosh 3 , |
| 178 | .Xr math 3 , |
| 179 | .Xr sin 3 , |
| 180 | .Xr sinh 3 , |
| 181 | .Xr tan 3 , |
| 182 | .Xr tanh 3 |
| 183 | .Sh STANDARDS |
| 184 | The |
| 185 | .Fn atan2 |
| 186 | function conforms to |
| 187 | .St -isoC . |