package org.josast.equationKepler;

import org.avmdti.josast.util.MathTools;

/**
 * <b>Description : Solve the Kepler Equation with the Fixed Point
 * Method</b>
 * 
 * <p>
 * Projet : JCP <BR><br>
 * <b>JOSAST</b> : Java Open Source Amateur Satellite  Toolbox  <br>
 * The aim of the project is to create a set of tools for amateur
 * satellite purpose. All this tools could be used together to create
 * specific software. <b>JOSAST</b> project is managed by AVMDTI (<A
 * HREF="http://www.avmdti.org">http://www.avmdti.org </a> ) <br>
 * This software is an open source software. Please read the <b><i>JOSAST
 * licence</i></b><BR>(<a
 * HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
 * </p>
 * 
 * <p>
 * for more information contact <a href="mailto:josast@avmdti.org">josast
 * at avmdti.org</a>
 * </p>
 *
 * @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
 * @version 1.0 <p><p>
 */
public class KeplerFixPpoint implements Kepler {
    //~ Static fields/initializers ----------------------------------------

    /** DOCUMENT ME! */
    static private final double DEFAULTPRECISION = 1.0e-14;

    /** DOCUMENT ME! */
    private static double epsilon = DEFAULTPRECISION;

    //~ Methods -----------------------------------------------------------

    /**
     * @see org.josast.equationKepler.Kepler#calcul()
     */
    public final double calcul(final double meanAnomaly,
        final double eccentricity) {
        double eccentricanomalie1; // Eccentric Anomaly utilisé pour 

        // les calculs
        double eccentricanomaliei1; // Eccentric Anomaly utilisé pour 

        //les calculs
        double error = 0; // erreur 
        double res; //

        eccentricanomalie1 = meanAnomaly; // Initial guess

        do {
            eccentricanomaliei1 = (eccentricity * Math.sin(eccentricanomalie1))
                + meanAnomaly;
            error = eccentricanomaliei1 - eccentricanomalie1;
            eccentricanomalie1 = eccentricanomaliei1;
        } while (MathTools.abs(error) >= epsilon);

        // tant que l'erreur est inférieur à une certaine valeur
        res = eccentricanomaliei1;

        return res;
    }

    /**
     * @see org.josast.equationKepler.Kepler#getEpsilon()
     */
    public final double getEpsilon() {
        return epsilon;
    }

    /**
     * @see org.josast.equationKepler.Kepler#setEpsilon(double)
     */
    public final void setEpsilon(final double epsilonl) {
        epsilon = epsilonl;
    }
}
