Blender V2.61 - r43446

frameacc.inl

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * \file  
00003  *      provides inline functions of rrframes.h
00004  *       
00005  *  \author 
00006  *      Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
00007  *
00008  *  \version 
00009  *      ORO_Geometry V0.2
00010  *
00011  *  \par History
00012  *      - $log$
00013  *
00014  *  \par Release
00015  *      $Name:  $ 
00016  ****************************************************************************/
00017 
00018 
00019 
00020 
00022 
00023 VectorAcc operator + (const VectorAcc& r1,const VectorAcc& r2) {
00024     return VectorAcc(r1.p+r2.p,r1.v+r2.v,r1.dv+r2.dv);
00025 }
00026 
00027 VectorAcc operator - (const VectorAcc& r1,const VectorAcc& r2) {
00028     return VectorAcc(r1.p-r2.p, r1.v-r2.v, r1.dv-r2.dv);
00029 }
00030 VectorAcc operator + (const Vector& r1,const VectorAcc& r2) {
00031     return VectorAcc(r1+r2.p,r2.v,r2.dv);
00032 }
00033 
00034 VectorAcc operator - (const Vector& r1,const VectorAcc& r2) {
00035     return VectorAcc(r1-r2.p, -r2.v, -r2.dv);
00036 }
00037 VectorAcc operator + (const VectorAcc& r1,const Vector& r2) {
00038     return VectorAcc(r1.p+r2,r1.v,r1.dv);
00039 }
00040 
00041 VectorAcc operator - (const VectorAcc& r1,const Vector& r2) {
00042     return VectorAcc(r1.p-r2, r1.v, r1.dv);
00043 }
00044 
00045 // unary -
00046 VectorAcc operator - (const VectorAcc& r) {
00047     return VectorAcc(-r.p,-r.v,-r.dv);
00048 }
00049 
00050 // cross prod.
00051 VectorAcc operator * (const VectorAcc& r1,const VectorAcc& r2) {
00052     return VectorAcc(r1.p*r2.p, 
00053                     r1.p*r2.v+r1.v*r2.p,
00054                     r1.dv*r2.p+2*r1.v*r2.v+r1.p*r2.dv
00055                     );
00056 }
00057 
00058 VectorAcc operator * (const VectorAcc& r1,const Vector& r2) {
00059     return VectorAcc(r1.p*r2, r1.v*r2, r1.dv*r2 );
00060 }
00061 
00062 VectorAcc operator * (const Vector& r1,const VectorAcc& r2) {
00063     return VectorAcc(r1*r2.p, r1*r2.v, r1*r2.dv );
00064 }
00065 
00066 
00067 
00068 // scalar mult.
00069 VectorAcc operator * (double r1,const VectorAcc& r2) {
00070     return VectorAcc(r1*r2.p, r1*r2.v, r1*r2.dv );
00071 }
00072 
00073 VectorAcc operator * (const VectorAcc& r1,double r2) {
00074     return VectorAcc(r1.p*r2, r1.v*r2, r1.dv*r2 );
00075 }
00076 
00077 VectorAcc operator * (const doubleAcc& r1,const VectorAcc& r2) {
00078     return VectorAcc(r1.t*r2.p, 
00079                    r1.t*r2.v  + r1.d*r2.p,
00080                    r1.t*r2.dv + 2*r1.d*r2.v + r1.dd*r2.p
00081                    );
00082 }
00083 
00084 VectorAcc operator * (const VectorAcc& r2,const doubleAcc& r1) {
00085     return VectorAcc(r1.t*r2.p, 
00086                r1.t*r2.v  + r1.d*r2.p,
00087                r1.t*r2.dv + 2*r1.d*r2.v + r1.dd*r2.p
00088                );
00089 }
00090 
00091 VectorAcc& VectorAcc::operator = (const VectorAcc& arg) {
00092     p=arg.p;
00093     v=arg.v;
00094     dv=arg.dv;
00095     return *this;
00096 }
00097 
00098 VectorAcc& VectorAcc::operator = (const Vector& arg) {
00099     p=arg;
00100     v=Vector::Zero();
00101     dv=Vector::Zero();
00102     return *this;
00103 }
00104 
00105 VectorAcc& VectorAcc::operator += (const VectorAcc& arg) {
00106     p+=arg.p;
00107     v+=arg.v;
00108     dv+= arg.dv;
00109     return *this;
00110 }
00111 VectorAcc& VectorAcc::operator -= (const VectorAcc& arg) {
00112     p-=arg.p;
00113     v-=arg.v;
00114     dv-=arg.dv;
00115     return *this;
00116 }
00117 
00118 VectorAcc VectorAcc::Zero() {
00119     return VectorAcc(Vector::Zero(),Vector::Zero(),Vector::Zero());
00120 }
00121 
00122 void VectorAcc::ReverseSign() {
00123     p.ReverseSign();
00124     v.ReverseSign();
00125     dv.ReverseSign();
00126 }
00127 
00128 doubleAcc VectorAcc::Norm() {
00129     doubleAcc res;
00130     res.t  = p.Norm();
00131     res.d  = dot(p,v)/res.t;
00132     res.dd = (dot(p,dv)+dot(v,v)-res.d*res.d)/res.t;
00133     return res;
00134 }
00135 
00136 doubleAcc dot(const VectorAcc& lhs,const VectorAcc& rhs) {
00137     return doubleAcc( dot(lhs.p,rhs.p),
00138                     dot(lhs.p,rhs.v)+dot(lhs.v,rhs.p),
00139                     dot(lhs.p,rhs.dv)+2*dot(lhs.v,rhs.v)+dot(lhs.dv,rhs.p)
00140                     );
00141 }
00142 
00143 doubleAcc dot(const VectorAcc& lhs,const Vector& rhs) {
00144     return doubleAcc( dot(lhs.p,rhs),
00145                      dot(lhs.v,rhs),
00146                      dot(lhs.dv,rhs)
00147                     );
00148 }
00149 
00150 doubleAcc dot(const Vector& lhs,const VectorAcc& rhs) {
00151     return doubleAcc( dot(lhs,rhs.p),
00152                     dot(lhs,rhs.v),
00153                     dot(lhs,rhs.dv)
00154                     );
00155 }
00156 
00157 
00158 bool Equal(const VectorAcc& r1,const VectorAcc& r2,double eps) {
00159     return (Equal(r1.p,r2.p,eps) 
00160          && Equal(r1.v,r2.v,eps)
00161          && Equal(r1.dv,r2.dv,eps)
00162          );
00163 }
00164 
00165 bool Equal(const Vector& r1,const VectorAcc& r2,double eps) {
00166     return (Equal(r1,r2.p,eps) 
00167          && Equal(Vector::Zero(),r2.v,eps)
00168          && Equal(Vector::Zero(),r2.dv,eps)
00169          );
00170 }
00171 
00172 bool Equal(const VectorAcc& r1,const Vector& r2,double eps) {
00173     return (Equal(r1.p,r2,eps) 
00174          && Equal(r1.v,Vector::Zero(),eps)
00175          && Equal(r1.dv,Vector::Zero(),eps)
00176          );
00177 }
00178 
00179 VectorAcc operator / (const VectorAcc& r1,double r2) {
00180     return r1*(1.0/r2);
00181 }
00182 
00183 VectorAcc operator / (const VectorAcc& r2,const doubleAcc& r1) {
00184     return r2*(1.0/r1);
00185 }
00186 
00187 
00188 
00190 
00191 RotationAcc operator* (const RotationAcc& r1,const RotationAcc& r2) {
00192     return RotationAcc( r1.R  * r2.R, 
00193                       r1.w  + r1.R*r2.w,  
00194                       r1.dw + r1.w*(r1.R*r2.w) + r1.R*r2.dw 
00195                       );
00196 }
00197 
00198 RotationAcc operator* (const Rotation& r1,const RotationAcc& r2) {
00199     return RotationAcc( r1*r2.R, r1*r2.w, r1*r2.dw);
00200 }
00201 
00202 RotationAcc operator* (const RotationAcc& r1,const Rotation& r2) {
00203     return RotationAcc( r1.R*r2, r1.w, r1.dw );
00204 }
00205 
00206 RotationAcc& RotationAcc::operator = (const RotationAcc& arg) {
00207     R=arg.R;
00208     w=arg.w;
00209     dw=arg.dw;
00210     return *this;
00211 }
00212 RotationAcc& RotationAcc::operator = (const Rotation& arg) {
00213     R = arg;
00214     w = Vector::Zero();
00215     dw = Vector::Zero();
00216     return *this;
00217 }
00218 
00219 RotationAcc RotationAcc::Identity() {
00220     return RotationAcc(Rotation::Identity(),Vector::Zero(),Vector::Zero());
00221 }
00222 
00223 RotationAcc RotationAcc::Inverse() const {
00224     return RotationAcc(R.Inverse(),-R.Inverse(w),-R.Inverse(dw));
00225 }
00226 
00227 VectorAcc RotationAcc::Inverse(const VectorAcc& arg) const {
00228     VectorAcc tmp;
00229     tmp.p  = R.Inverse(arg.p);
00230     tmp.v  = R.Inverse(arg.v - w * arg.p);
00231     tmp.dv = R.Inverse(arg.dv - dw*arg.p - w*(arg.v+R*tmp.v));
00232     return tmp;
00233 }
00234 
00235 VectorAcc RotationAcc::Inverse(const Vector& arg) const {
00236     VectorAcc tmp;
00237     tmp.p  = R.Inverse(arg);
00238     tmp.v  = R.Inverse(-w*arg);
00239     tmp.dv = R.Inverse(-dw*arg - w*(R*tmp.v));
00240     return tmp;
00241 }
00242 
00243 
00244 VectorAcc RotationAcc::operator*(const VectorAcc& arg) const {
00245     VectorAcc tmp;
00246     tmp.p = R*arg.p;
00247     tmp.dv = R*arg.v;
00248     tmp.v = w*tmp.p + tmp.dv;
00249     tmp.dv = dw*tmp.p + w*(tmp.v + tmp.dv) + R*arg.dv;
00250     return tmp;
00251 }
00252 
00253 VectorAcc operator*(const Rotation& R,const VectorAcc& x) {
00254     return VectorAcc(R*x.p,R*x.v,R*x.dv);
00255 }
00256 
00257 VectorAcc RotationAcc::operator*(const Vector& arg) const {
00258     VectorAcc tmp;
00259     tmp.p = R*arg;
00260     tmp.v = w*tmp.p;
00261     tmp.dv = dw*tmp.p + w*tmp.v;
00262     return tmp;
00263 }
00264 
00265 /*
00266         // = Rotations
00267         // The Rot... static functions give the value of the appropriate rotation matrix back.
00268         // The DoRot... functions apply a rotation R to *this,such that *this = *this * R.
00269 
00270         void RRotation::DoRotX(const RDouble& angle) {
00271             w+=R*Vector(angle.grad,0,0);
00272             R.DoRotX(angle.t);
00273         }
00274 RotationAcc RotationAcc::RotX(const doubleAcc& angle) {
00275     return RotationAcc(Rotation::RotX(angle.t),
00276                       Vector(angle.d,0,0),
00277                       Vector(angle.dd,0,0)
00278                       );
00279 }
00280 
00281         void RRotation::DoRotY(const RDouble& angle) {
00282             w+=R*Vector(0,angle.grad,0);
00283             R.DoRotY(angle.t);
00284         }
00285 RotationAcc RotationAcc::RotY(const doubleAcc& angle) {
00286     return RotationAcc(
00287               Rotation::RotX(angle.t),
00288               Vector(0,angle.d,0),
00289               Vector(0,angle.dd,0)
00290             );
00291 }
00292 
00293         void RRotation::DoRotZ(const RDouble& angle) {
00294             w+=R*Vector(0,0,angle.grad);
00295             R.DoRotZ(angle.t);
00296         }
00297 RotationAcc RotationAcc::RotZ(const doubleAcc& angle) {
00298     return RotationAcc(
00299                 Rotation::RotZ(angle.t),
00300                 Vector(0,0,angle.d),
00301                 Vector(0,0,angle.dd)
00302             );
00303 }
00304 
00305 
00306         RRotation RRotation::Rot(const Vector& rotvec,const RDouble& angle) 
00307         // rotvec has arbitrary norm
00308         // rotation around a constant vector !
00309         {
00310             Vector v = rotvec.Normalize();
00311             return RRotation(Rotation::Rot2(v,angle.t),v*angle.grad);
00312         }
00313 
00314         RRotation RRotation::Rot2(const Vector& rotvec,const RDouble& angle) 
00315             // rotvec is normalized.
00316         {
00317             return RRotation(Rotation::Rot2(rotvec,angle.t),rotvec*angle.grad);
00318         }
00319 
00320 */
00321 
00322 bool Equal(const RotationAcc& r1,const RotationAcc& r2,double eps) {
00323     return (Equal(r1.w,r2.w,eps) && Equal(r1.R,r2.R,eps) && Equal(r1.dw,r2.dw,eps) );
00324 }
00325 bool Equal(const Rotation& r1,const RotationAcc& r2,double eps) {
00326     return (Equal(Vector::Zero(),r2.w,eps) && Equal(r1,r2.R,eps) && 
00327             Equal(Vector::Zero(),r2.dw,eps) );
00328 }
00329 bool Equal(const RotationAcc& r1,const Rotation& r2,double eps) {
00330     return (Equal(r1.w,Vector::Zero(),eps) && Equal(r1.R,r2,eps) && 
00331             Equal(r1.dw,Vector::Zero(),eps) );
00332 }
00333 
00334 
00335 // Methods and operators related to FrameAcc
00336 // They all delegate most of the work to RotationAcc and VectorAcc
00337 FrameAcc& FrameAcc::operator = (const FrameAcc& arg) {
00338     M=arg.M;
00339     p=arg.p;
00340     return *this;
00341 }
00342 
00343 FrameAcc FrameAcc::Identity() {
00344     return FrameAcc(RotationAcc::Identity(),VectorAcc::Zero());
00345 }
00346 
00347 
00348 FrameAcc operator *(const FrameAcc& lhs,const FrameAcc& rhs)
00349 {
00350     return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
00351 }
00352 FrameAcc operator *(const FrameAcc& lhs,const Frame& rhs)
00353 {
00354     return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
00355 }
00356 FrameAcc operator *(const Frame& lhs,const FrameAcc& rhs)
00357 {
00358     return FrameAcc(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
00359 }
00360 
00361 VectorAcc FrameAcc::operator *(const VectorAcc & arg) const
00362 {
00363     return M*arg+p;
00364 }
00365 VectorAcc FrameAcc::operator *(const Vector & arg) const
00366 {
00367     return M*arg+p;
00368 }
00369 
00370 VectorAcc FrameAcc::Inverse(const VectorAcc& arg) const
00371 {
00372     return M.Inverse(arg-p);
00373 }
00374 
00375 VectorAcc FrameAcc::Inverse(const Vector& arg) const
00376 {
00377     return M.Inverse(arg-p);
00378 }
00379 
00380 FrameAcc FrameAcc::Inverse() const
00381 {
00382     return FrameAcc(M.Inverse(),-M.Inverse(p));
00383 }
00384 
00385 FrameAcc& FrameAcc::operator =(const Frame & arg)
00386 { 
00387     M = arg.M;
00388     p = arg.p;
00389     return *this;
00390 }
00391 
00392 bool Equal(const FrameAcc& r1,const FrameAcc& r2,double eps) {
00393     return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
00394 }
00395 bool Equal(const Frame& r1,const FrameAcc& r2,double eps) {
00396     return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
00397 }
00398 bool Equal(const FrameAcc& r1,const Frame& r2,double eps) {
00399     return (Equal(r1.M,r2.M,eps) && Equal(r1.p,r2.p,eps));
00400 }
00401 
00402 
00403 Frame FrameAcc::GetFrame() const {
00404     return Frame(M.R,p.p);
00405 }
00406 
00407 
00408 Twist FrameAcc::GetTwist() const {
00409     return Twist(p.v,M.w);
00410 }
00411 
00412 
00413 Twist FrameAcc::GetAccTwist() const {
00414     return Twist(p.dv,M.dw);
00415 }
00416 
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424 
00425 
00426 
00427 
00428 
00429 
00430 
00431 
00432 
00433 TwistAcc TwistAcc::Zero()
00434 {
00435     return TwistAcc(VectorAcc::Zero(),VectorAcc::Zero());
00436 }
00437 
00438 
00439 void TwistAcc::ReverseSign()
00440 {   
00441     vel.ReverseSign();
00442     rot.ReverseSign();
00443 }
00444 
00445 TwistAcc TwistAcc::RefPoint(const VectorAcc& v_base_AB)
00446      // Changes the reference point of the TwistAcc.
00447      // The RVector v_base_AB is expressed in the same base as the TwistAcc
00448      // The RVector v_base_AB is a RVector from the old point to
00449      // the new point.
00450      // Complexity : 6M+6A
00451 {
00452     return TwistAcc(this->vel+this->rot*v_base_AB,this->rot);
00453 }
00454 
00455 TwistAcc& TwistAcc::operator-=(const TwistAcc& arg)
00456 {
00457     vel-=arg.vel;
00458     rot -=arg.rot;
00459     return *this;
00460 }
00461 
00462 TwistAcc& TwistAcc::operator+=(const TwistAcc& arg)
00463 {
00464     vel+=arg.vel;
00465     rot +=arg.rot;
00466     return *this;
00467 }
00468 
00469 
00470 TwistAcc operator*(const TwistAcc& lhs,double rhs)
00471 {
00472     return TwistAcc(lhs.vel*rhs,lhs.rot*rhs);
00473 }
00474 
00475 TwistAcc operator*(double lhs,const TwistAcc& rhs)
00476 {
00477     return TwistAcc(lhs*rhs.vel,lhs*rhs.rot);
00478 }
00479 
00480 TwistAcc operator/(const TwistAcc& lhs,double rhs)
00481 {
00482     return TwistAcc(lhs.vel/rhs,lhs.rot/rhs);
00483 }
00484 
00485 
00486 TwistAcc operator*(const TwistAcc& lhs,const doubleAcc& rhs)
00487 {
00488     return TwistAcc(lhs.vel*rhs,lhs.rot*rhs);
00489 }
00490 
00491 TwistAcc operator*(const doubleAcc& lhs,const TwistAcc& rhs)
00492 {
00493     return TwistAcc(lhs*rhs.vel,lhs*rhs.rot);
00494 }
00495 
00496 TwistAcc operator/(const TwistAcc& lhs,const doubleAcc& rhs)
00497 {
00498     return TwistAcc(lhs.vel/rhs,lhs.rot/rhs);
00499 }
00500 
00501 
00502 
00503 // addition of TwistAcc's
00504 TwistAcc operator+(const TwistAcc& lhs,const TwistAcc& rhs)
00505 {
00506     return TwistAcc(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
00507 }
00508 
00509 TwistAcc operator-(const TwistAcc& lhs,const TwistAcc& rhs)
00510 {
00511     return TwistAcc(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
00512 }
00513 
00514 // unary -
00515 TwistAcc operator-(const TwistAcc& arg) 
00516 {
00517     return TwistAcc(-arg.vel,-arg.rot);
00518 }
00519 
00520 
00521 
00522 
00523 
00524 TwistAcc RotationAcc::Inverse(const TwistAcc& arg) const
00525 {
00526     return TwistAcc(Inverse(arg.vel),Inverse(arg.rot));
00527 }
00528 
00529 TwistAcc RotationAcc::operator * (const TwistAcc& arg) const
00530 {
00531     return TwistAcc((*this)*arg.vel,(*this)*arg.rot);
00532 }
00533 
00534 TwistAcc RotationAcc::Inverse(const Twist& arg) const
00535 {
00536     return TwistAcc(Inverse(arg.vel),Inverse(arg.rot));
00537 }
00538 
00539 TwistAcc RotationAcc::operator * (const Twist& arg) const
00540 {
00541     return TwistAcc((*this)*arg.vel,(*this)*arg.rot);
00542 }
00543 
00544 
00545 TwistAcc FrameAcc::operator * (const TwistAcc& arg) const
00546 {
00547     TwistAcc tmp;
00548     tmp.rot = M*arg.rot;
00549     tmp.vel = M*arg.vel+p*tmp.rot;
00550     return tmp;
00551 }
00552 
00553 TwistAcc FrameAcc::operator * (const Twist& arg) const
00554 {
00555     TwistAcc tmp;
00556     tmp.rot = M*arg.rot;
00557     tmp.vel = M*arg.vel+p*tmp.rot;
00558     return tmp;
00559 }
00560 
00561 TwistAcc FrameAcc::Inverse(const TwistAcc& arg) const
00562 {
00563     TwistAcc tmp;
00564     tmp.rot =  M.Inverse(arg.rot);
00565     tmp.vel = M.Inverse(arg.vel-p*arg.rot);
00566     return tmp;
00567 }
00568 
00569 TwistAcc FrameAcc::Inverse(const Twist& arg) const
00570 {
00571     TwistAcc tmp;
00572     tmp.rot =  M.Inverse(arg.rot);
00573     tmp.vel = M.Inverse(arg.vel-p*arg.rot);
00574     return tmp;
00575 }
00576 
00577 Twist TwistAcc::GetTwist() const {
00578     return Twist(vel.p,rot.p);
00579 }
00580 
00581 Twist TwistAcc::GetTwistDot() const {
00582     return Twist(vel.v,rot.v);
00583 }
00584 
00585 bool Equal(const TwistAcc& a,const TwistAcc& b,double eps) {
00586         return (Equal(a.rot,b.rot,eps)&&
00587                 Equal(a.vel,b.vel,eps)  );
00588 }
00589 bool Equal(const Twist& a,const TwistAcc& b,double eps) {
00590         return (Equal(a.rot,b.rot,eps)&&
00591                 Equal(a.vel,b.vel,eps)  );
00592 }
00593 bool Equal(const TwistAcc& a,const Twist& b,double eps) {
00594         return (Equal(a.rot,b.rot,eps)&&
00595                 Equal(a.vel,b.vel,eps)  );
00596 }
00597