2008-03-28 13:56:47 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
2008-06-27 17:06:23 -07:00
|
|
|
package math
|
2008-03-28 13:56:47 -07:00
|
|
|
|
2008-11-19 16:14:31 -08:00
|
|
|
import "math"
|
2008-03-28 13:56:47 -07:00
|
|
|
|
|
|
|
|
/*
|
2008-07-08 20:48:41 -07:00
|
|
|
* atan2 discovers what quadrant the angle
|
|
|
|
|
* is in and calls atan.
|
|
|
|
|
*/
|
2009-01-20 14:40:40 -08:00
|
|
|
func Atan2(arg1, arg2 float64) float64 {
|
2008-03-28 13:56:47 -07:00
|
|
|
if arg1+arg2 == arg1 {
|
|
|
|
|
if arg1 >= 0 {
|
2009-01-15 19:11:32 -08:00
|
|
|
return Pi/2;
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
2009-01-15 19:11:32 -08:00
|
|
|
return -Pi/2;
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
2008-11-19 16:14:31 -08:00
|
|
|
x := Atan(arg1/arg2);
|
2008-03-28 13:56:47 -07:00
|
|
|
if arg2 < 0 {
|
|
|
|
|
if x <= 0 {
|
2009-01-15 19:11:32 -08:00
|
|
|
return x + Pi;
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
2009-01-15 19:11:32 -08:00
|
|
|
return x - Pi;
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
|
|
|
|
return x;
|
|
|
|
|
}
|