src/Level2/EAngles.cc
/* These are checking functions for Euler angles. They insure that the angles
   always reside within the class specified ranges:

                 alpha = gamma = [0,360)       beta = [0,180]
   
   Some care must be taken when the user inputs one or more angles that lie
   outside of these ranges.  For alpha and gamma one may simply add/subtract
   n*2*PI until the angles are within their specified ranges. For angle beta,
   since it does not span [0, 360), this does not entirely work! We can start
   by setting beta to be within [-PI, PI] & if it lies within [0, PI] all
   is OK. However, if beta lies within [-PI, 0) then the actual beta rotation
   angle should be |beta|.... but this does not account for the proper
   rotation of the x & y axes, their direction of rotation is reversed. To
   compensate we must add an additional PI rotation to both alpha & gamma.   */
These are checking functions for Euler angles. They insure that the angles
always reside within the class specified ranges.



Some care must be taken when the user inputs one or more angles that lie
outside of these ranges.  For alpha and gamma one may simply add/subtract
n*2*PI until the angles are within their specified ranges. For angle beta,
since it does not span [0, 360), this does not entirely work. We can start
by setting beta to be within [-PI, PI] & if it lies within [0, PI] all
is OK. However, if beta lies within [-PI, 0) then the actual beta rotation
angle should be |beta|.... but this does not account for the proper
rotation of the x & y axes, their direction of rotation is reversed. To
compensate we must add an additional PI rotation to both alpha & gamma.
These are checking functions for Euler angles . They insure that the angles always reside within the class specified ranges . Some care must be taken when the user inputs one or more angles that lie outside of these ranges . For alpha and gamma one may simply add / subtract n * 2 * PI until the angles are within their specified ranges . For angle beta since it does not span [ 0 360 ) this does not entirely work . We can start by setting beta to be within [ - PI PI ] & if it lies within [ 0 PI ] all is OK . However if beta lies within [ - PI 0 ) then the actual beta rotation angle should be |beta| .... but this does not account for the proper rotation of the x & y axes their direction of rotation is reversed . To compensate we must add an additional PI rotation to both alpha & gamma .
void EAngles::SetAngles(double alpha, double beta, double gamma, bool deg)
  {
  if(deg)					
    {						
    alpha *= DEG2RAD;				
    beta  *= DEG2RAD;				
    gamma *= DEG2RAD;
    }
  _alpha = fmod(alpha, PIx2);			
  while(_alpha <  0.0)  { _alpha += PIx2; }	
  while(_alpha >= PIx2) { _alpha -= PIx2; }	
  if(fabs(_alpha)      < AngCutoff) _alpha=0;	
  if(fabs(_alpha-PIx2) < AngCutoff) _alpha=0;	
  _gamma = fmod(gamma, PIx2);			
  while(_gamma < 0.0)   { _gamma += PIx2; }	
  while(_gamma >= PIx2) { _gamma -= PIx2; }	
  if(fabs(_gamma)      < AngCutoff) _gamma=0;	
  if(fabs(_gamma-PIx2) < AngCutoff) _gamma=0;	 
//  _beta = fmod(beta, PIx2);			
  _beta = beta;
  while(_beta < -PI)   { _beta += PIx2; }	
  while(_beta >  PI)   { _beta -= PIx2; }	
  if(fabs(_beta)      < AngCutoff) _beta=0;	
  if(fabs(_beta-PI)   < AngCutoff) _beta=PI;	
  if(_beta >= 0) return;			
  _beta = -_beta;				
  if(fabs(_beta)      < AngCutoff) _beta=0;	
  if(fabs(_beta-PI)   < AngCutoff) _beta=PI;	
  _alpha += PI;
  _alpha = fmod(_alpha, PIx2);			
  if(fabs(_alpha)      < AngCutoff) _alpha=0;	
  if(fabs(_alpha-PIx2) < AngCutoff) _alpha=0;	
  _gamma += PI;
  _gamma = fmod(_gamma, PIx2);			
  if(fabs(_gamma)      < AngCutoff) _gamma=0;	
  if(fabs(_gamma-PIx2) < AngCutoff) _gamma=0;	
  }
void EAngles :: SetAngles ( double alpha , double beta , double gamma , bool deg ) { if ( deg ) { alpha *= DEG2RAD ; beta *= DEG2RAD ; gamma *= DEG2RAD ; } _alpha = fmod ( alpha , PIx2 ) ; while ( _alpha < 0.0 ) { _alpha += PIx2 ; } while ( _alpha >= PIx2 ) { _alpha -= PIx2 ; } if ( fabs ( _alpha ) < AngCutoff ) _alpha = 0 ; if ( fabs ( _alpha - PIx2 ) < AngCutoff ) _alpha = 0 ; _gamma = fmod ( gamma , PIx2 ) ; while ( _gamma < 0.0 ) { _gamma += PIx2 ; } while ( _gamma >= PIx2 ) { _gamma -= PIx2 ; } if ( fabs ( _gamma ) < AngCutoff ) _gamma = 0 ; if ( fabs ( _gamma - PIx2 ) < AngCutoff ) _gamma = 0 ; _beta = beta ; while ( _beta < - PI ) { _beta += PIx2 ; } while ( _beta > PI ) { _beta -= PIx2 ; } if ( fabs ( _beta ) < AngCutoff ) _beta = 0 ; if ( fabs ( _beta - PI ) < AngCutoff ) _beta = PI ; if ( _beta >= 0 ) return ; _beta = - _beta ; if ( fabs ( _beta ) < AngCutoff ) _beta = 0 ; if ( fabs ( _beta - PI ) < AngCutoff ) _beta = PI ; _alpha += PI ; _alpha = fmod ( _alpha , PIx2 ) ; if ( fabs ( _alpha ) < AngCutoff ) _alpha = 0 ; if ( fabs ( _alpha - PIx2 ) < AngCutoff ) _alpha = 0 ; _gamma += PI ; _gamma = fmod ( _gamma , PIx2 ) ; if ( fabs ( _gamma ) < AngCutoff ) _gamma = 0 ; if ( fabs ( _gamma - PIx2 ) < AngCutoff ) _gamma = 0 ; }
These are checking functions for Euler angles.
These are checking functions for Euler angles .
// If angles input in degrees // convert them to radians // ALL Euler angles are kept // in radians (internally) // Insure alpha = [0, 360) //   If < 0,    add n*2*PI //   If > 2*PI, sub n*2*PI //   If ~0,    make exactly 0 //   If ~2*PI, make exactly 0 // Insure beta = [0, 360) //   If < 0,    add n*2*PI //   If > 2*PI, sub n*2*PI //   If ~0,    make exactly 0 //   If ~2*PI, make exactly 0  //  _beta = fmod(beta, PIx2);			// Insure beta = [0, 360) //   If < -PI, add n*2*PI //   If >  PI, add n*2*PI //   If ~0, make exactly 0 //   If ~ PI, make exactly PI // If beta = [0, PI] done // If beta = [-PI,0)  //   If ~0, make exactly 0 //   If ~ PI, make exactly PI // Insure alpha = [0, 360) //   If ~0,    make exactly 0 //   If ~2*PI, make exactly 0 // Insure alpha = [0, 360) //   If ~0,    make exactly 0 //   If ~2*PI, make exactly 0