framevel.inl

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

Generated on Wed Nov 23 19:00:15 2011 for FreeCAD by  doxygen 1.6.1