예제 #1
0
파일: kepler.go 프로젝트: soniakeys/meeus
// Kepler3 solves Kepler's equation by binary search.
//
// Argument e is eccentricity, M is mean anomaly.
//
// Result E is eccentric anomaly.
func Kepler3(e float64, M unit.Angle) (E unit.Angle) {
	// adapted from BASIC, p. 206
	MR := M.Mod1().Rad()
	f := 1
	if MR > math.Pi {
		f = -1
		MR = 2*math.Pi - MR
	}
	E0 := math.Pi * .5
	d := math.Pi * .25
	for i := 0; i < 53; i++ {
		M1 := E0 - e*math.Sin(E0)
		if MR-M1 < 0 {
			E0 -= d
		} else {
			E0 += d
		}
		d *= .5
	}
	if f < 0 {
		E0 = -E0
	}
	return unit.Angle(E0)
}