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