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