/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : Math.h                                                        */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _MATH_H
#define _MATH_H
static char Math_h_id[] = "$Header: /data/altex/Master/auv/altex/onboard/utils/MathP.h,v 1.1 2001/06/02 21:33:54 hthomas Exp $";

/*
$Log: MathP.h,v $
Revision 1.1  2001/06/02 21:33:54  hthomas
various changes; remove stale entries in root makefile, fixed file naming to allow for serving from windows, and fixed makefiles to avoid file linking/unlinking problem in makedepend when talking through samba to windows boxes

Revision 1.5  2000/08/21 20:54:20  oreilly
Added round() method

Revision 1.4  2000/05/02 21:08:57  rob
Added RpmToRadps conversion constant.

Revision 1.3  2000/02/07 20:59:22  pean
Added revised header to include Proprietary Information

Revision 1.2  2000/01/19 06:13:44  oreilly
Debug vers of matherr()

Revision 1.1  1999/12/07 23:03:07  pean
Created utils subdirectory and moved source files here to help manage sources

Revision 1.6  1999/12/04 01:06:38  rob
Added "static" to the declarations of the new functions.

Revision 1.5  1999/12/03 23:21:32  rob
Moved some functions from DynamicControl here.

Revision 1.4  1999/11/19 19:19:07  oreilly
*** empty log message ***

Revision 1.3  1999/10/12 23:17:48  oreilly
*** empty log message ***

Revision 1.2  1999/09/15 23:03:42  pean
Added kvh compass interface module

Revision 1.1  1999/09/09 18:39:37  oreilly
*** empty log message ***

Revision 1.3  1997/04/09 16:34:48  oreilly
include "trig.h"

 * Revision 1.2  96/10/28  09:00:15  09:00:15  oreilly (Thomas C. O'Reilly)
 * Math utilities
 * 
 * Revision 1.1  96/08/14  13:30:39  13:30:39  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/


#include <math.h>
#define M_PI          3.14159265358979323846

#ifndef PI
#define PI          3.14159265358979323846
#endif


// Indices for vectors
#define X 0
#define Y 1
#define Z 2

typedef double Radians;

/*
CLASS 
Math

DESCRIPTION
Various static utility methods, including angular conversions.

AUTHOR
Tom O'Reilly
*/
class Math
{
  public:
  
  ///////////////////////////////////////////////////////////////////
  // 2 times pi
  static const double TwoPi;

  ///////////////////////////////////////////////////////////////////
  // Radians per degree
  static const double RadsPerDeg;

  ///////////////////////////////////////////////////////////////////
  // Degrees per radian
  static const double DegsPerRad;

  ///////////////////////////////////////////////////////////////////
  // Convert rpm to radians per second
  static const double RpmToRadps;
  
  ///////////////////////////////////////////////////////////////////
  // Normalize angle so it is in range 0 to 2PI
  static void zeroToTwoPi(Radians *angle);

  ///////////////////////////////////////////////////////////////////
  // Normalize angle so it is in range -PI to PI
  static void minusPiToPi(Radians *pitch);

  ///////////////////////////////////////////////////////////////////
  // Angular separation in clockwise direction
  static Radians angularSeparation(Radians start, Radians stop);

  ///////////////////////////////////////////////////////////////////
  // Convert and angle in degs to an angle in radians
  static Radians degToRad(double deg);

  ///////////////////////////////////////////////////////////////////
  // Convert and angle in radians to an angle in degrees
  static double radToDeg(Radians rads);

  ///////////////////////////////////////////////////////////////////
  // Simple limit function:
  static double limit( double value, double max, double min );

  ///////////////////////////////////////////////////////////////////
  // sgn function:
  static double sgn( double x );

  ///////////////////////////////////////////////////////////////////
  // modulo Pi function:
  static double modPi( double angle );
  
  ///////////////////////////////////////////////////////////////////
  // Round to nearest integer (QNX has no rint()!!!)
  static int round(double x);
};


// Our version of matherr(), for debugging
extern "C" {
  int matherr(struct exception *error);
};
#endif
