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