I’am bad mathematic, but I need to translate PHP mathematical routine to Objective C, to calculate in iOS application.
I have this code, in PHP, it is working ok:
function torad ( $arg ) { return ($arg * (pi() / 180.0)); }
function kepler ( $m, $ecc ) {
$EPSILON = 1e-6;
$m = torad( $m );
$e = $m;
do {
$delta = $e - $ecc * sin( $e ) - $m;
$e -= $delta / ( 1 - $ecc * cos($e) );
} while ( abs($delta) > $EPSILON );
return ( $e );
}
This is code, I have in Objective C (for iOS):
+ (double) toRad:(double)arg{
return (arg * (3.14159265 / 180.0)); // 3.14159265 = pi()
}
+ (double) kepler:(double)m ecc:(double)ecc {
double EPSILON = 1e-6;
double _m = [self toRad:m];
double e = _m;
double delta;
do {
delta = e - ecc * sin(e) - m;
e -= delta / (1 - ecc * cos(e));
} while (abs(delta) > EPSILON);
return e;
}
Kepler function works wrong.
Maybe, you can tell, where I was wrong?
Thanks.
You are using
minstead of_min this line: