Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Measures.cc

Go to the documentation of this file.
00001 #include "Shared/Measures.h"
00002 
00003 PlaneEquation::PlaneEquation(const fmat::Column<3> &dir, float disp) : direction(dir), displacement(disp) {
00004   float const n = direction.norm();
00005   displacement /= n;
00006   direction /= n;
00007 }
00008 
00009 PlaneEquation::PlaneEquation(float a, float b, float c, float d) : direction(fmat::pack(a,b,c)), displacement(d) {
00010   float const n = direction.norm();
00011   displacement /= n;
00012   direction /= n;
00013 }
00014 
00015 std::ostream& operator<<(std::ostream &os, const PlaneEquation &p) {
00016   os << "PlaneEquation{" << p.getDirection() << " = " << p.getDisplacement() << "}";
00017   return os;
00018 }
00019 
00020 //================================================================
00021 
00022 void AngPi::normalize() {
00023   if ( value >= Pi) {
00024     if ( value < TwoPi ) {
00025       value -= Pi;
00026     } else { // use fmod only if necessary
00027       value = std::fmod(value,Pi);
00028     }
00029   } else if ( value < 0 ) {
00030     if ( value > -Pi ) {
00031       value += Pi;
00032     } else { // use fmod only if necessary
00033       value = std::fmod(value,Pi);
00034       if(value<0) // this is almost always true except when value==0, leave it there
00035         value += Pi;
00036     }
00037   }
00038 }
00039 
00040 
00041 AngPi angdist(AngPi const &arg1, AngPi const &arg2) {
00042   AngPi diff = arg1.value - arg2.value;
00043   if ( diff > Pi/2 )
00044     diff = Pi - diff;
00045   return diff;
00046 }
00047 
00048 void AngTwoPi::normalize() {
00049   if ( value >= TwoPi) {
00050     if ( value < 2*TwoPi ) {
00051       value -= TwoPi;
00052     } else { // use fmod only if necessary
00053       value = std::fmod(value,TwoPi);
00054     }
00055   } else if ( value < 0 ) {
00056     if ( value > -TwoPi ) {
00057       value += TwoPi;
00058     } else { // use fmod only if necessary
00059       value = std::fmod(value,TwoPi);
00060       if(value<0) // this is almost always true except when value==0, leave it there
00061         value += TwoPi;
00062     }
00063   }
00064 }        
00065 
00066 AngPi angdist(AngTwoPi const &arg1, AngTwoPi const &arg2) {
00067   AngTwoPi diff = arg1.value - arg2.value;
00068   if ( diff > Pi )
00069     diff = TwoPi - diff;
00070   return AngPi(diff);
00071 }
00072 
00073 void AngSignPi::normalize() {
00074   if ( value > Pi ) {
00075     if ( value <= TwoPi ) {
00076       value -= TwoPi;
00077     } else { // use fmod only if necessary
00078       value = std::fmod(value,TwoPi);
00079       if( value > Pi )
00080         value -= TwoPi;
00081     }
00082   } else if ( value <= -Pi ) {
00083     if ( value >= -TwoPi ) {
00084       value += TwoPi;
00085     } else { // use fmod only if necessary
00086       value = std::fmod(value,TwoPi);
00087       if( value <= -Pi )
00088         value += TwoPi;
00089     }
00090   }
00091 }        
00092 
00093 AngPi angdist(AngSignPi const &arg1, AngSignPi const &arg2) {
00094   AngSignPi diff = arg1.value - arg2.value;
00095   if ( diff > Pi )
00096     diff = TwoPi - diff;
00097   return AngPi(diff);
00098 }
00099 
00100 void AngSignTwoPi::normalize() {
00101   if ( value >= TwoPi) {
00102     if ( value < 2*TwoPi )
00103       value -= TwoPi;
00104     else // use fmod only if necessary
00105       value = std::fmod(value,TwoPi);
00106   } else if ( value < -TwoPi ) {
00107     if ( value > -2*TwoPi )
00108       value += TwoPi;
00109     else  // use fmod only if necessary
00110       value = std::fmod(value,TwoPi);
00111   }
00112 }

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:44 2016 by Doxygen 1.6.3