/**
 * 
 * <b>Description : </b> 
 * 
 * 
 * <p>Projet : JOSAST <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</b></i><BR>(<A HREF="http://www.avmdti.org">http://www.avmdti.org </a> )
 * <p>for more information contact <a href="mailto:josast@avmdti.org">josast@avmdti.org</a></p>
 * @author  <a href="mailto:mercier.josast@avmdti.org">mercier</a>
 * @version 1.0
 * <p><b><i> Source Update </b></i></p>
 * <br> Version : date 		: name 		: comments 
 * <br> V1      : 2 mars 2004	: C. Mercier 	: create file
 * <p>
 * 
 */
package org.avmdti.josast.util;


/**
 * 
 * Misc Class
 * 
 * @author Xtophe
 * @version 1.0
 *
 */
public class Misc {
	/**
	* fonction utilitaire
	*
	*/

	private static double twopi = (Math.PI * 2.);

	/**
	 * Convert a longitude between -180 degree to 180 degree
	 * <br>
	 * @param longitude in degree
	 * @return longitude in degree
	 */
	public static double  convertlong(double longitude) {
		double _longitude = longitude;
		while (_longitude > 180) {
			_longitude = _longitude - 360;
		}
		return (_longitude);
	}
	
	/**
	 *  Arcos function 
	 *  <br>
	 * @param x 
	 * @param y
	 * @return
	 */
	public static double arccos(double x, double y) {
			double result = 0.0;
			double fraction = x / y;
			if ((x > 0.0) && (y > 0.0))
				result = Math.acos(fraction);
			if ((x > 0.0) && (y > 0.0))
				result = Math.acos(fraction);
			if ((x < 0.0) && (y > 0.0))
				result = Math.PI + Math.acos(fraction);
			if ((x > 0.0) && (y < 0.0))
				result = Math.PI + Math.acos(fraction);
			return (result);
		}
	
	/**
	 * 
	 * @param x in radian
	 * @return radian 
	 */
	public static  double FMod2p(double x) {
		// double rval = Math.fmod( x, twopi);
		double tmp = x / twopi;
		double rval = x - Math.rint(tmp) * twopi;

		if (rval < 0.)
			rval += twopi;
		return (rval);
	}
	/* ACTAN */
		/* We can't just use the "usual" C atan2( ) function,  because the output
		   range we need has to run from 0 to pi instead of -pi to pi.  So... */
		
	/**
	 * We can't just use the "usual" C atan2( ) function,  because the output
	 * range we need has to run from 0 to pi instead of -pi to pi.  So...
	 * @param sinx
	 * @param cosx
	 * @return actan;
	 */
	public static double AcTan(double sinx, double cosx) {
			return (Math.PI + Math.atan2(-sinx, -cosx));
		} /*Function actan*/

}
