frames.inl 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /***************************************************************************
  2. frames.inl - description
  3. -------------------------
  4. begin : June 2006
  5. copyright : (C) 2006 Erwin Aertbelien
  6. email : firstname.lastname@mech.kuleuven.ac.be
  7. History (only major changes)( AUTHOR-Description ) :
  8. ***************************************************************************
  9. * This library is free software; you can redistribute it and/or *
  10. * modify it under the terms of the GNU Lesser General Public *
  11. * License as published by the Free Software Foundation; either *
  12. * version 2.1 of the License, or (at your option) any later version. *
  13. * *
  14. * This library is distributed in the hope that it will be useful, *
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  17. * Lesser General Public License for more details. *
  18. * *
  19. * You should have received a copy of the GNU Lesser General Public *
  20. * License along with this library; if not, write to the Free Software *
  21. * Foundation, Inc., 51 Franklin Street, *
  22. * Fifth Floor, Boston, MA 02110-1301, USA. *
  23. * *
  24. ***************************************************************************/
  25. IMETHOD Vector::Vector(const Vector & arg)
  26. {
  27. data[0] = arg.data[0];
  28. data[1] = arg.data[1];
  29. data[2] = arg.data[2];
  30. }
  31. IMETHOD Vector::Vector(double x,double y, double z)
  32. {
  33. data[0]=x;data[1]=y;data[2]=z;
  34. }
  35. IMETHOD Vector::Vector(double* xyz)
  36. {
  37. data[0]=xyz[0];data[1]=xyz[1];data[2]=xyz[2];
  38. }
  39. IMETHOD Vector::Vector(float* xyz)
  40. {
  41. data[0]=xyz[0];data[1]=xyz[1];data[2]=xyz[2];
  42. }
  43. IMETHOD void Vector::GetValue(double* xyz) const
  44. {
  45. xyz[0]=data[0];xyz[1]=data[1];xyz[2]=data[2];
  46. }
  47. IMETHOD Vector& Vector::operator =(const Vector & arg)
  48. {
  49. data[0] = arg.data[0];
  50. data[1] = arg.data[1];
  51. data[2] = arg.data[2];
  52. return *this;
  53. }
  54. IMETHOD Vector operator +(const Vector & lhs,const Vector& rhs)
  55. {
  56. Vector tmp;
  57. tmp.data[0] = lhs.data[0]+rhs.data[0];
  58. tmp.data[1] = lhs.data[1]+rhs.data[1];
  59. tmp.data[2] = lhs.data[2]+rhs.data[2];
  60. return tmp;
  61. }
  62. IMETHOD Vector operator -(const Vector & lhs,const Vector& rhs)
  63. {
  64. Vector tmp;
  65. tmp.data[0] = lhs.data[0]-rhs.data[0];
  66. tmp.data[1] = lhs.data[1]-rhs.data[1];
  67. tmp.data[2] = lhs.data[2]-rhs.data[2];
  68. return tmp;
  69. }
  70. IMETHOD double Vector::x() const { return data[0]; }
  71. IMETHOD double Vector::y() const { return data[1]; }
  72. IMETHOD double Vector::z() const { return data[2]; }
  73. IMETHOD void Vector::x( double _x ) { data[0] = _x; }
  74. IMETHOD void Vector::y( double _y ) { data[1] = _y; }
  75. IMETHOD void Vector::z( double _z ) { data[2] = _z; }
  76. Vector operator *(const Vector& lhs,double rhs)
  77. {
  78. Vector tmp;
  79. tmp.data[0] = lhs.data[0]*rhs;
  80. tmp.data[1] = lhs.data[1]*rhs;
  81. tmp.data[2] = lhs.data[2]*rhs;
  82. return tmp;
  83. }
  84. Vector operator *(double lhs,const Vector& rhs)
  85. {
  86. Vector tmp;
  87. tmp.data[0] = lhs*rhs.data[0];
  88. tmp.data[1] = lhs*rhs.data[1];
  89. tmp.data[2] = lhs*rhs.data[2];
  90. return tmp;
  91. }
  92. Vector operator /(const Vector& lhs,double rhs)
  93. {
  94. Vector tmp;
  95. tmp.data[0] = lhs.data[0]/rhs;
  96. tmp.data[1] = lhs.data[1]/rhs;
  97. tmp.data[2] = lhs.data[2]/rhs;
  98. return tmp;
  99. }
  100. Vector operator *(const Vector & lhs,const Vector& rhs)
  101. // Complexity : 6M+3A
  102. {
  103. Vector tmp;
  104. tmp.data[0] = lhs.data[1]*rhs.data[2]-lhs.data[2]*rhs.data[1];
  105. tmp.data[1] = lhs.data[2]*rhs.data[0]-lhs.data[0]*rhs.data[2];
  106. tmp.data[2] = lhs.data[0]*rhs.data[1]-lhs.data[1]*rhs.data[0];
  107. return tmp;
  108. }
  109. Vector& Vector::operator +=(const Vector & arg)
  110. // Complexity : 3A
  111. {
  112. data[0]+=arg.data[0];
  113. data[1]+=arg.data[1];
  114. data[2]+=arg.data[2];
  115. return *this;
  116. }
  117. Vector& Vector::operator -=(const Vector & arg)
  118. // Complexity : 3A
  119. {
  120. data[0]-=arg.data[0];
  121. data[1]-=arg.data[1];
  122. data[2]-=arg.data[2];
  123. return *this;
  124. }
  125. Vector& Vector::operator *=(double arg)
  126. {
  127. data[0] *= arg;
  128. data[1] *= arg;
  129. data[2] *= arg;
  130. return *this;
  131. }
  132. Vector Vector::Zero()
  133. {
  134. return Vector(0,0,0);
  135. }
  136. double Vector::operator()(int index) const {
  137. FRAMES_CHECKI((0<=index)&&(index<=2));
  138. return data[index];
  139. }
  140. double& Vector::operator () (int index)
  141. {
  142. FRAMES_CHECKI((0<=index)&&(index<=2));
  143. return data[index];
  144. }
  145. IMETHOD Vector Normalize(const Vector& a, double eps)
  146. {
  147. double l=a.Norm();
  148. return (l<eps) ? Vector(0.0,0.0,0.0) : a/l;
  149. }
  150. Wrench Frame::operator * (const Wrench& arg) const
  151. // Complexity : 24M+18A
  152. {
  153. Wrench tmp;
  154. tmp.force = M*arg.force;
  155. tmp.torque = M*arg.torque + p*tmp.force;
  156. return tmp;
  157. }
  158. Wrench Frame::Inverse(const Wrench& arg) const
  159. {
  160. Wrench tmp;
  161. tmp.force = M.Inverse(arg.force);
  162. tmp.torque = M.Inverse(arg.torque-p*arg.force);
  163. return tmp;
  164. }
  165. Wrench Rotation::Inverse(const Wrench& arg) const
  166. {
  167. return Wrench(Inverse(arg.force),Inverse(arg.torque));
  168. }
  169. Twist Rotation::Inverse(const Twist& arg) const
  170. {
  171. return Twist(Inverse(arg.vel),Inverse(arg.rot));
  172. }
  173. Wrench Wrench::Zero()
  174. {
  175. return Wrench(Vector::Zero(),Vector::Zero());
  176. }
  177. void Wrench::ReverseSign()
  178. {
  179. torque.ReverseSign();
  180. force.ReverseSign();
  181. }
  182. Wrench Wrench::RefPoint(const Vector& v_base_AB) const
  183. // Changes the reference point of the Wrench.
  184. // The vector v_base_AB is expressed in the same base as the twist
  185. // The vector v_base_AB is a vector from the old point to
  186. // the new point.
  187. {
  188. return Wrench(this->force,
  189. this->torque+this->force*v_base_AB
  190. );
  191. }
  192. Wrench& Wrench::operator-=(const Wrench& arg)
  193. {
  194. torque-=arg.torque;
  195. force -=arg.force;
  196. return *this;
  197. }
  198. Wrench& Wrench::operator+=(const Wrench& arg)
  199. {
  200. torque+=arg.torque;
  201. force +=arg.force;
  202. return *this;
  203. }
  204. double& Wrench::operator()(int i)
  205. {
  206. // assert((0<=i)&&(i<6)); done by underlying routines
  207. if (i<3)
  208. return force(i);
  209. else
  210. return torque(i-3);
  211. }
  212. double Wrench::operator()(int i) const
  213. {
  214. // assert((0<=i)&&(i<6)); done by underlying routines
  215. if (i<3)
  216. return force(i);
  217. else
  218. return torque(i-3);
  219. }
  220. Wrench operator*(const Wrench& lhs,double rhs)
  221. {
  222. return Wrench(lhs.force*rhs,lhs.torque*rhs);
  223. }
  224. Wrench operator*(double lhs,const Wrench& rhs)
  225. {
  226. return Wrench(lhs*rhs.force,lhs*rhs.torque);
  227. }
  228. Wrench operator/(const Wrench& lhs,double rhs)
  229. {
  230. return Wrench(lhs.force/rhs,lhs.torque/rhs);
  231. }
  232. // addition of Wrench's
  233. Wrench operator+(const Wrench& lhs,const Wrench& rhs)
  234. {
  235. return Wrench(lhs.force+rhs.force,lhs.torque+rhs.torque);
  236. }
  237. Wrench operator-(const Wrench& lhs,const Wrench& rhs)
  238. {
  239. return Wrench(lhs.force-rhs.force,lhs.torque-rhs.torque);
  240. }
  241. // unary -
  242. Wrench operator-(const Wrench& arg)
  243. {
  244. return Wrench(-arg.force,-arg.torque);
  245. }
  246. Twist Frame::operator * (const Twist& arg) const
  247. // Complexity : 24M+18A
  248. {
  249. Twist tmp;
  250. tmp.rot = M*arg.rot;
  251. tmp.vel = M*arg.vel+p*tmp.rot;
  252. return tmp;
  253. }
  254. Twist Frame::Inverse(const Twist& arg) const
  255. {
  256. Twist tmp;
  257. tmp.rot = M.Inverse(arg.rot);
  258. tmp.vel = M.Inverse(arg.vel-p*arg.rot);
  259. return tmp;
  260. }
  261. Twist Twist::Zero()
  262. {
  263. return Twist(Vector::Zero(),Vector::Zero());
  264. }
  265. void Twist::ReverseSign()
  266. {
  267. vel.ReverseSign();
  268. rot.ReverseSign();
  269. }
  270. Twist Twist::RefPoint(const Vector& v_base_AB) const
  271. // Changes the reference point of the twist.
  272. // The vector v_base_AB is expressed in the same base as the twist
  273. // The vector v_base_AB is a vector from the old point to
  274. // the new point.
  275. // Complexity : 6M+6A
  276. {
  277. return Twist(this->vel+this->rot*v_base_AB,this->rot);
  278. }
  279. Twist& Twist::operator-=(const Twist& arg)
  280. {
  281. vel-=arg.vel;
  282. rot -=arg.rot;
  283. return *this;
  284. }
  285. Twist& Twist::operator+=(const Twist& arg)
  286. {
  287. vel+=arg.vel;
  288. rot +=arg.rot;
  289. return *this;
  290. }
  291. double& Twist::operator()(int i)
  292. {
  293. // assert((0<=i)&&(i<6)); done by underlying routines
  294. if (i<3)
  295. return vel(i);
  296. else
  297. return rot(i-3);
  298. }
  299. double Twist::operator()(int i) const
  300. {
  301. // assert((0<=i)&&(i<6)); done by underlying routines
  302. if (i<3)
  303. return vel(i);
  304. else
  305. return rot(i-3);
  306. }
  307. Twist operator*(const Twist& lhs,double rhs)
  308. {
  309. return Twist(lhs.vel*rhs,lhs.rot*rhs);
  310. }
  311. Twist operator*(double lhs,const Twist& rhs)
  312. {
  313. return Twist(lhs*rhs.vel,lhs*rhs.rot);
  314. }
  315. Twist operator/(const Twist& lhs,double rhs)
  316. {
  317. return Twist(lhs.vel/rhs,lhs.rot/rhs);
  318. }
  319. // addition of Twist's
  320. Twist operator+(const Twist& lhs,const Twist& rhs)
  321. {
  322. return Twist(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
  323. }
  324. Twist operator-(const Twist& lhs,const Twist& rhs)
  325. {
  326. return Twist(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
  327. }
  328. // unary -
  329. Twist operator-(const Twist& arg)
  330. {
  331. return Twist(-arg.vel,-arg.rot);
  332. }
  333. Frame::Frame(const Rotation & R)
  334. {
  335. M=R;
  336. p=Vector::Zero();
  337. }
  338. Frame::Frame(const Vector & V)
  339. {
  340. M = Rotation::Identity();
  341. p = V;
  342. }
  343. Frame::Frame(const Rotation & R, const Vector & V)
  344. {
  345. M = R;
  346. p = V;
  347. }
  348. Frame operator *(const Frame& lhs,const Frame& rhs)
  349. // Complexity : 36M+36A
  350. {
  351. return Frame(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
  352. }
  353. Vector Frame::operator *(const Vector & arg) const
  354. {
  355. return M*arg+p;
  356. }
  357. Vector Frame::Inverse(const Vector& arg) const
  358. {
  359. return M.Inverse(arg-p);
  360. }
  361. Frame Frame::Inverse() const
  362. {
  363. return Frame(M.Inverse(),-M.Inverse(p));
  364. }
  365. Frame& Frame::operator =(const Frame & arg)
  366. {
  367. M = arg.M;
  368. p = arg.p;
  369. return *this;
  370. }
  371. Frame::Frame(const Frame & arg) :
  372. p(arg.p),M(arg.M)
  373. {}
  374. void Vector::ReverseSign()
  375. {
  376. data[0] = -data[0];
  377. data[1] = -data[1];
  378. data[2] = -data[2];
  379. }
  380. Vector operator-(const Vector & arg)
  381. {
  382. Vector tmp;
  383. tmp.data[0]=-arg.data[0];
  384. tmp.data[1]=-arg.data[1];
  385. tmp.data[2]=-arg.data[2];
  386. return tmp;
  387. }
  388. void Vector::Set2DXY(const Vector2& v)
  389. // a 3D vector where the 2D vector v is put in the XY plane
  390. {
  391. data[0]=v(0);
  392. data[1]=v(1);
  393. data[2]=0;
  394. }
  395. void Vector::Set2DYZ(const Vector2& v)
  396. // a 3D vector where the 2D vector v is put in the YZ plane
  397. {
  398. data[1]=v(0);
  399. data[2]=v(1);
  400. data[0]=0;
  401. }
  402. void Vector::Set2DZX(const Vector2& v)
  403. // a 3D vector where the 2D vector v is put in the ZX plane
  404. {
  405. data[2]=v(0);
  406. data[0]=v(1);
  407. data[1]=0;
  408. }
  409. double& Rotation::operator()(int i,int j) {
  410. FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
  411. return data[i*3+j];
  412. }
  413. double Rotation::operator()(int i,int j) const {
  414. FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
  415. return data[i*3+j];
  416. }
  417. Rotation::Rotation( double Xx,double Yx,double Zx,
  418. double Xy,double Yy,double Zy,
  419. double Xz,double Yz,double Zz)
  420. {
  421. data[0] = Xx;data[1]=Yx;data[2]=Zx;
  422. data[3] = Xy;data[4]=Yy;data[5]=Zy;
  423. data[6] = Xz;data[7]=Yz;data[8]=Zz;
  424. }
  425. Rotation::Rotation(const Vector& x,const Vector& y,const Vector& z)
  426. {
  427. data[0] = x.data[0];data[3] = x.data[1];data[6] = x.data[2];
  428. data[1] = y.data[0];data[4] = y.data[1];data[7] = y.data[2];
  429. data[2] = z.data[0];data[5] = z.data[1];data[8] = z.data[2];
  430. }
  431. Rotation& Rotation::operator=(const Rotation& arg) {
  432. int count=9;
  433. while (count--) data[count] = arg.data[count];
  434. return *this;
  435. }
  436. Vector Rotation::operator*(const Vector& v) const {
  437. // Complexity : 9M+6A
  438. return Vector(
  439. data[0]*v.data[0] + data[1]*v.data[1] + data[2]*v.data[2],
  440. data[3]*v.data[0] + data[4]*v.data[1] + data[5]*v.data[2],
  441. data[6]*v.data[0] + data[7]*v.data[1] + data[8]*v.data[2]
  442. );
  443. }
  444. Twist Rotation::operator * (const Twist& arg) const
  445. // Transformation of the base to which the twist is expressed.
  446. // look at Frame*Twist for a transformation that also transforms
  447. // the velocity reference point.
  448. // Complexity : 18M+12A
  449. {
  450. return Twist((*this)*arg.vel,(*this)*arg.rot);
  451. }
  452. Wrench Rotation::operator * (const Wrench& arg) const
  453. // Transformation of the base to which the wrench is expressed.
  454. // look at Frame*Twist for a transformation that also transforms
  455. // the force reference point.
  456. {
  457. return Wrench((*this)*arg.force,(*this)*arg.torque);
  458. }
  459. Rotation Rotation::Identity() {
  460. return Rotation(1,0,0,0,1,0,0,0,1);
  461. }
  462. // *this = *this * ROT(X,angle)
  463. void Rotation::DoRotX(double angle)
  464. {
  465. double cs = cos(angle);
  466. double sn = sin(angle);
  467. double x1,x2,x3;
  468. x1 = cs* (*this)(0,1) + sn* (*this)(0,2);
  469. x2 = cs* (*this)(1,1) + sn* (*this)(1,2);
  470. x3 = cs* (*this)(2,1) + sn* (*this)(2,2);
  471. (*this)(0,2) = -sn* (*this)(0,1) + cs* (*this)(0,2);
  472. (*this)(1,2) = -sn* (*this)(1,1) + cs* (*this)(1,2);
  473. (*this)(2,2) = -sn* (*this)(2,1) + cs* (*this)(2,2);
  474. (*this)(0,1) = x1;
  475. (*this)(1,1) = x2;
  476. (*this)(2,1) = x3;
  477. }
  478. void Rotation::DoRotY(double angle)
  479. {
  480. double cs = cos(angle);
  481. double sn = sin(angle);
  482. double x1,x2,x3;
  483. x1 = cs* (*this)(0,0) - sn* (*this)(0,2);
  484. x2 = cs* (*this)(1,0) - sn* (*this)(1,2);
  485. x3 = cs* (*this)(2,0) - sn* (*this)(2,2);
  486. (*this)(0,2) = sn* (*this)(0,0) + cs* (*this)(0,2);
  487. (*this)(1,2) = sn* (*this)(1,0) + cs* (*this)(1,2);
  488. (*this)(2,2) = sn* (*this)(2,0) + cs* (*this)(2,2);
  489. (*this)(0,0) = x1;
  490. (*this)(1,0) = x2;
  491. (*this)(2,0) = x3;
  492. }
  493. void Rotation::DoRotZ(double angle)
  494. {
  495. double cs = cos(angle);
  496. double sn = sin(angle);
  497. double x1,x2,x3;
  498. x1 = cs* (*this)(0,0) + sn* (*this)(0,1);
  499. x2 = cs* (*this)(1,0) + sn* (*this)(1,1);
  500. x3 = cs* (*this)(2,0) + sn* (*this)(2,1);
  501. (*this)(0,1) = -sn* (*this)(0,0) + cs* (*this)(0,1);
  502. (*this)(1,1) = -sn* (*this)(1,0) + cs* (*this)(1,1);
  503. (*this)(2,1) = -sn* (*this)(2,0) + cs* (*this)(2,1);
  504. (*this)(0,0) = x1;
  505. (*this)(1,0) = x2;
  506. (*this)(2,0) = x3;
  507. }
  508. Rotation Rotation::RotX(double angle) {
  509. double cs=cos(angle);
  510. double sn=sin(angle);
  511. return Rotation(1,0,0,0,cs,-sn,0,sn,cs);
  512. }
  513. Rotation Rotation::RotY(double angle) {
  514. double cs=cos(angle);
  515. double sn=sin(angle);
  516. return Rotation(cs,0,sn,0,1,0,-sn,0,cs);
  517. }
  518. Rotation Rotation::RotZ(double angle) {
  519. double cs=cos(angle);
  520. double sn=sin(angle);
  521. return Rotation(cs,-sn,0,sn,cs,0,0,0,1);
  522. }
  523. void Frame::Integrate(const Twist& t_this,double samplefrequency)
  524. {
  525. double n = t_this.rot.Norm()/samplefrequency;
  526. if (n<epsilon) {
  527. p += M*(t_this.vel/samplefrequency);
  528. } else {
  529. (*this) = (*this) *
  530. Frame ( Rotation::Rot( t_this.rot, n ),
  531. t_this.vel/samplefrequency
  532. );
  533. }
  534. }
  535. Rotation Rotation::Inverse() const
  536. {
  537. Rotation tmp(*this);
  538. tmp.SetInverse();
  539. return tmp;
  540. }
  541. Vector Rotation::Inverse(const Vector& v) const {
  542. return Vector(
  543. data[0]*v.data[0] + data[3]*v.data[1] + data[6]*v.data[2],
  544. data[1]*v.data[0] + data[4]*v.data[1] + data[7]*v.data[2],
  545. data[2]*v.data[0] + data[5]*v.data[1] + data[8]*v.data[2]
  546. );
  547. }
  548. void Rotation::setValue(float* oglmat)
  549. {
  550. data[0] = *oglmat++; data[3] = *oglmat++; data[6] = *oglmat++; oglmat++;
  551. data[1] = *oglmat++; data[4] = *oglmat++; data[7] = *oglmat++; oglmat++;
  552. data[2] = *oglmat++; data[5] = *oglmat++; data[8] = *oglmat;
  553. Ortho();
  554. }
  555. void Rotation::getValue(float* oglmat) const
  556. {
  557. *oglmat++ = (float)data[0]; *oglmat++ = (float)data[3]; *oglmat++ = (float)data[6]; *oglmat++ = 0.f;
  558. *oglmat++ = (float)data[1]; *oglmat++ = (float)data[4]; *oglmat++ = (float)data[7]; *oglmat++ = 0.f;
  559. *oglmat++ = (float)data[2]; *oglmat++ = (float)data[5]; *oglmat++ = (float)data[8]; *oglmat++ = 0.f;
  560. *oglmat++ = 0.f; *oglmat++ = 0.f; *oglmat++ = 0.f; *oglmat = 1.f;
  561. }
  562. void Rotation::SetInverse()
  563. {
  564. double tmp;
  565. tmp = data[1];data[1]=data[3];data[3]=tmp;
  566. tmp = data[2];data[2]=data[6];data[6]=tmp;
  567. tmp = data[5];data[5]=data[7];data[7]=tmp;
  568. }
  569. double Frame::operator()(int i,int j) {
  570. FRAMES_CHECKI((0<=i)&&(i<=3)&&(0<=j)&&(j<=3));
  571. if (i==3) {
  572. if (j==3)
  573. return 1.0;
  574. else
  575. return 0.0;
  576. } else {
  577. if (j==3)
  578. return p(i);
  579. else
  580. return M(i,j);
  581. }
  582. }
  583. double Frame::operator()(int i,int j) const {
  584. FRAMES_CHECKI((0<=i)&&(i<=3)&&(0<=j)&&(j<=3));
  585. if (i==3) {
  586. if (j==3)
  587. return 1;
  588. else
  589. return 0;
  590. } else {
  591. if (j==3)
  592. return p(i);
  593. else
  594. return M(i,j);
  595. }
  596. }
  597. Frame Frame::Identity() {
  598. return Frame(Rotation::Identity(),Vector::Zero());
  599. }
  600. void Frame::setValue(float* oglmat)
  601. {
  602. M.setValue(oglmat);
  603. p.data[0] = oglmat[12];
  604. p.data[1] = oglmat[13];
  605. p.data[2] = oglmat[14];
  606. }
  607. void Frame::getValue(float* oglmat) const
  608. {
  609. M.getValue(oglmat);
  610. oglmat[12] = (float)p.data[0];
  611. oglmat[13] = (float)p.data[1];
  612. oglmat[14] = (float)p.data[2];
  613. }
  614. void Vector::Set2DPlane(const Frame& F_someframe_XY,const Vector2& v_XY)
  615. // a 3D vector where the 2D vector v is put in the XY plane of the frame
  616. // F_someframe_XY.
  617. {
  618. Vector tmp_XY;
  619. tmp_XY.Set2DXY(v_XY);
  620. tmp_XY = F_someframe_XY*(tmp_XY);
  621. }
  622. //============ 2 dimensional version of the frames objects =============
  623. IMETHOD Vector2::Vector2(const Vector2 & arg)
  624. {
  625. data[0] = arg.data[0];
  626. data[1] = arg.data[1];
  627. }
  628. IMETHOD Vector2::Vector2(double x,double y)
  629. {
  630. data[0]=x;data[1]=y;
  631. }
  632. IMETHOD Vector2::Vector2(double* xy)
  633. {
  634. data[0]=xy[0];data[1]=xy[1];
  635. }
  636. IMETHOD Vector2::Vector2(float* xy)
  637. {
  638. data[0]=xy[0];data[1]=xy[1];
  639. }
  640. IMETHOD Vector2& Vector2::operator =(const Vector2 & arg)
  641. {
  642. data[0] = arg.data[0];
  643. data[1] = arg.data[1];
  644. return *this;
  645. }
  646. IMETHOD void Vector2::GetValue(double* xy) const
  647. {
  648. xy[0]=data[0];xy[1]=data[1];
  649. }
  650. IMETHOD Vector2 operator +(const Vector2 & lhs,const Vector2& rhs)
  651. {
  652. return Vector2(lhs.data[0]+rhs.data[0],lhs.data[1]+rhs.data[1]);
  653. }
  654. IMETHOD Vector2 operator -(const Vector2 & lhs,const Vector2& rhs)
  655. {
  656. return Vector2(lhs.data[0]-rhs.data[0],lhs.data[1]-rhs.data[1]);
  657. }
  658. IMETHOD Vector2 operator *(const Vector2& lhs,double rhs)
  659. {
  660. return Vector2(lhs.data[0]*rhs,lhs.data[1]*rhs);
  661. }
  662. IMETHOD Vector2 operator *(double lhs,const Vector2& rhs)
  663. {
  664. return Vector2(lhs*rhs.data[0],lhs*rhs.data[1]);
  665. }
  666. IMETHOD Vector2 operator /(const Vector2& lhs,double rhs)
  667. {
  668. return Vector2(lhs.data[0]/rhs,lhs.data[1]/rhs);
  669. }
  670. IMETHOD Vector2& Vector2::operator +=(const Vector2 & arg)
  671. {
  672. data[0]+=arg.data[0];
  673. data[1]+=arg.data[1];
  674. return *this;
  675. }
  676. IMETHOD Vector2& Vector2::operator -=(const Vector2 & arg)
  677. {
  678. data[0]-=arg.data[0];
  679. data[1]-=arg.data[1];
  680. return *this;
  681. }
  682. IMETHOD Vector2 Vector2::Zero() {
  683. return Vector2(0,0);
  684. }
  685. IMETHOD double Vector2::operator()(int index) const {
  686. FRAMES_CHECKI((0<=index)&&(index<=1));
  687. return data[index];
  688. }
  689. IMETHOD double& Vector2::operator () (int index)
  690. {
  691. FRAMES_CHECKI((0<=index)&&(index<=1));
  692. return data[index];
  693. }
  694. IMETHOD void Vector2::ReverseSign()
  695. {
  696. data[0] = -data[0];
  697. data[1] = -data[1];
  698. }
  699. IMETHOD Vector2 operator-(const Vector2 & arg)
  700. {
  701. return Vector2(-arg.data[0],-arg.data[1]);
  702. }
  703. IMETHOD void Vector2::Set3DXY(const Vector& v)
  704. // projects v in its XY plane, and sets *this to these values
  705. {
  706. data[0]=v(0);
  707. data[1]=v(1);
  708. }
  709. IMETHOD void Vector2::Set3DYZ(const Vector& v)
  710. // projects v in its XY plane, and sets *this to these values
  711. {
  712. data[0]=v(1);
  713. data[1]=v(2);
  714. }
  715. IMETHOD void Vector2::Set3DZX(const Vector& v)
  716. // projects v in its XY plane, and and sets *this to these values
  717. {
  718. data[0]=v(2);
  719. data[1]=v(0);
  720. }
  721. IMETHOD void Vector2::Set3DPlane(const Frame& F_someframe_XY,const Vector& v_someframe)
  722. // projects v in the XY plane of F_someframe_XY, and sets *this to these values
  723. // expressed wrt someframe.
  724. {
  725. Vector tmp = F_someframe_XY.Inverse(v_someframe);
  726. data[0]=tmp(0);
  727. data[1]=tmp(1);
  728. }
  729. IMETHOD Rotation2& Rotation2::operator=(const Rotation2& arg) {
  730. c=arg.c;s=arg.s;
  731. return *this;
  732. }
  733. IMETHOD Vector2 Rotation2::operator*(const Vector2& v) const {
  734. return Vector2(v.data[0]*c-v.data[1]*s,v.data[0]*s+v.data[1]*c);
  735. }
  736. IMETHOD double Rotation2::operator()(int i,int j) const {
  737. FRAMES_CHECKI((0<=i)&&(i<=1)&&(0<=j)&&(j<=1));
  738. if (i==j) return c;
  739. if (i==0)
  740. return s;
  741. else
  742. return -s;
  743. }
  744. IMETHOD Rotation2 operator *(const Rotation2& lhs,const Rotation2& rhs) {
  745. return Rotation2(lhs.c*rhs.c-lhs.s*rhs.s,lhs.s*rhs.c+lhs.c*rhs.s);
  746. }
  747. IMETHOD void Rotation2::SetInverse() {
  748. s=-s;
  749. }
  750. IMETHOD Rotation2 Rotation2::Inverse() const {
  751. return Rotation2(c,-s);
  752. }
  753. IMETHOD Vector2 Rotation2::Inverse(const Vector2& v) const {
  754. return Vector2(v.data[0]*c+v.data[1]*s,-v.data[0]*s+v.data[1]*c);
  755. }
  756. IMETHOD Rotation2 Rotation2::Identity() {
  757. return Rotation2(1,0);
  758. }
  759. IMETHOD void Rotation2::SetIdentity()
  760. {
  761. c = 1;
  762. s = 0;
  763. }
  764. IMETHOD void Rotation2::SetRot(double angle) {
  765. c=cos(angle);s=sin(angle);
  766. }
  767. IMETHOD Rotation2 Rotation2::Rot(double angle) {
  768. return Rotation2(cos(angle),sin(angle));
  769. }
  770. IMETHOD double Rotation2::GetRot() const {
  771. return atan2(s,c);
  772. }
  773. IMETHOD Frame2::Frame2() {
  774. }
  775. IMETHOD Frame2::Frame2(const Rotation2 & R)
  776. {
  777. M=R;
  778. p=Vector2::Zero();
  779. }
  780. IMETHOD Frame2::Frame2(const Vector2 & V)
  781. {
  782. M = Rotation2::Identity();
  783. p = V;
  784. }
  785. IMETHOD Frame2::Frame2(const Rotation2 & R, const Vector2 & V)
  786. {
  787. M = R;
  788. p = V;
  789. }
  790. IMETHOD Frame2 operator *(const Frame2& lhs,const Frame2& rhs)
  791. {
  792. return Frame2(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
  793. }
  794. IMETHOD Vector2 Frame2::operator *(const Vector2 & arg)
  795. {
  796. return M*arg+p;
  797. }
  798. IMETHOD Vector2 Frame2::Inverse(const Vector2& arg) const
  799. {
  800. return M.Inverse(arg-p);
  801. }
  802. IMETHOD void Frame2::SetIdentity()
  803. {
  804. M.SetIdentity();
  805. p = Vector2::Zero();
  806. }
  807. IMETHOD void Frame2::SetInverse()
  808. {
  809. M.SetInverse();
  810. p = M*p;
  811. p.ReverseSign();
  812. }
  813. IMETHOD Frame2 Frame2::Inverse() const
  814. {
  815. Frame2 tmp(*this);
  816. tmp.SetInverse();
  817. return tmp;
  818. }
  819. IMETHOD Frame2& Frame2::operator =(const Frame2 & arg)
  820. {
  821. M = arg.M;
  822. p = arg.p;
  823. return *this;
  824. }
  825. IMETHOD Frame2::Frame2(const Frame2 & arg) :
  826. p(arg.p), M(arg.M)
  827. {}
  828. IMETHOD double Frame2::operator()(int i,int j) {
  829. FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
  830. if (i==2) {
  831. if (j==2)
  832. return 1;
  833. else
  834. return 0;
  835. } else {
  836. if (j==2)
  837. return p(i);
  838. else
  839. return M(i,j);
  840. }
  841. }
  842. IMETHOD double Frame2::operator()(int i,int j) const {
  843. FRAMES_CHECKI((0<=i)&&(i<=2)&&(0<=j)&&(j<=2));
  844. if (i==2) {
  845. if (j==2)
  846. return 1;
  847. else
  848. return 0;
  849. } else {
  850. if (j==2)
  851. return p(i);
  852. else
  853. return M(i,j);
  854. }
  855. }
  856. // Scalar products.
  857. IMETHOD double dot(const Vector& lhs,const Vector& rhs) {
  858. return rhs(0)*lhs(0)+rhs(1)*lhs(1)+rhs(2)*lhs(2);
  859. }
  860. IMETHOD double dot(const Twist& lhs,const Wrench& rhs) {
  861. return dot(lhs.vel,rhs.force)+dot(lhs.rot,rhs.torque);
  862. }
  863. IMETHOD double dot(const Wrench& rhs,const Twist& lhs) {
  864. return dot(lhs.vel,rhs.force)+dot(lhs.rot,rhs.torque);
  865. }
  866. // Equality operators
  867. IMETHOD bool Equal(const Vector& a,const Vector& b,double eps) {
  868. return (Equal(a.data[0],b.data[0],eps)&&
  869. Equal(a.data[1],b.data[1],eps)&&
  870. Equal(a.data[2],b.data[2],eps) );
  871. }
  872. IMETHOD bool Equal(const Frame& a,const Frame& b,double eps) {
  873. return (Equal(a.p,b.p,eps)&&
  874. Equal(a.M,b.M,eps) );
  875. }
  876. IMETHOD bool Equal(const Wrench& a,const Wrench& b,double eps) {
  877. return (Equal(a.force,b.force,eps)&&
  878. Equal(a.torque,b.torque,eps) );
  879. }
  880. IMETHOD bool Equal(const Twist& a,const Twist& b,double eps) {
  881. return (Equal(a.rot,b.rot,eps)&&
  882. Equal(a.vel,b.vel,eps) );
  883. }
  884. IMETHOD bool Equal(const Vector2& a,const Vector2& b,double eps) {
  885. return (Equal(a.data[0],b.data[0],eps)&&
  886. Equal(a.data[1],b.data[1],eps) );
  887. }
  888. IMETHOD bool Equal(const Rotation2& a,const Rotation2& b,double eps) {
  889. return ( Equal(a.c,b.c,eps) && Equal(a.s,b.s,eps) );
  890. }
  891. IMETHOD bool Equal(const Frame2& a,const Frame2& b,double eps) {
  892. return (Equal(a.p,b.p,eps)&&
  893. Equal(a.M,b.M,eps) );
  894. }
  895. IMETHOD void SetToZero(Vector& v) {
  896. v=Vector::Zero();
  897. }
  898. IMETHOD void SetToZero(Twist& v) {
  899. SetToZero(v.rot);
  900. SetToZero(v.vel);
  901. }
  902. IMETHOD void SetToZero(Wrench& v) {
  903. SetToZero(v.force);
  904. SetToZero(v.torque);
  905. }
  906. IMETHOD void SetToZero(Vector2& v) {
  907. v = Vector2::Zero();
  908. }
  909. ////////////////////////////////////////////////////////////////
  910. // The following defines the operations
  911. // diff
  912. // addDelta
  913. // random
  914. // posrandom
  915. // on all the types defined in this library.
  916. // (mostly for uniform integration, differentiation and testing).
  917. // Defined as functions because double is not a class and a method
  918. // would brake uniformity when defined for a double.
  919. ////////////////////////////////////////////////////////////////
  920. /**
  921. * axis_a_b is a rotation vector, its norm is a rotation angle
  922. * axis_a_b rotates the a frame towards the b frame.
  923. * This routine returns the rotation matrix R_a_b
  924. */
  925. IMETHOD Rotation Rot(const Vector& axis_a_b) {
  926. // The formula is
  927. // V.(V.tr) + st*[V x] + ct*(I-V.(V.tr))
  928. // can be found by multiplying it with an arbitrary vector p
  929. // and noting that this vector is rotated.
  930. Vector rotvec = axis_a_b;
  931. double angle = rotvec.Normalize(1E-10);
  932. double ct = ::cos(angle);
  933. double st = ::sin(angle);
  934. double vt = 1-ct;
  935. return Rotation(
  936. ct + vt*rotvec(0)*rotvec(0),
  937. -rotvec(2)*st + vt*rotvec(0)*rotvec(1),
  938. rotvec(1)*st + vt*rotvec(0)*rotvec(2),
  939. rotvec(2)*st + vt*rotvec(1)*rotvec(0),
  940. ct + vt*rotvec(1)*rotvec(1),
  941. -rotvec(0)*st + vt*rotvec(1)*rotvec(2),
  942. -rotvec(1)*st + vt*rotvec(2)*rotvec(0),
  943. rotvec(0)*st + vt*rotvec(2)*rotvec(1),
  944. ct + vt*rotvec(2)*rotvec(2)
  945. );
  946. }
  947. IMETHOD Vector diff(const Vector& a,const Vector& b,double dt) {
  948. return (b-a)/dt;
  949. }
  950. /**
  951. * \brief diff operator for displacement rotational velocity.
  952. *
  953. * The Vector arguments here represent a displacement rotational velocity. i.e. a rotation
  954. * around a fixed axis for a certain angle. For this representation you cannot use diff() but
  955. * have to use diff_displ().
  956. *
  957. * \TODO represent a displacement twist and displacement rotational velocity with another
  958. * class, instead of Vector and Twist.
  959. * \warning do not confuse displacement rotational velocities and velocities
  960. * \warning do not confuse displacement twist and twist.
  961. *
  962. IMETHOD Vector diff_displ(const Vector& a,const Vector& b,double dt) {
  963. return diff(Rot(a),Rot(b),dt);
  964. }*/
  965. /**
  966. * \brief diff operator for displacement twist.
  967. *
  968. * The Twist arguments here represent a displacement twist. i.e. a rotation
  969. * around a fixed axis for a certain angle. For this representation you cannot use diff() but
  970. * have to use diff_displ().
  971. *
  972. * \warning do not confuse displacement rotational velocities and velocities
  973. * \warning do not confuse displacement twist and twist.
  974. *
  975. IMETHOD Twist diff_displ(const Twist& a,const Twist& b,double dt) {
  976. return Twist(diff(a.vel,b.vel,dt),diff(Rot(a.rot),Rot(b.rot),dt));
  977. }
  978. */
  979. IMETHOD Vector diff(const Rotation& R_a_b1,const Rotation& R_a_b2,double dt) {
  980. Rotation R_b1_b2(R_a_b1.Inverse()*R_a_b2);
  981. return R_a_b1 * R_b1_b2.GetRot() / dt;
  982. }
  983. IMETHOD Twist diff(const Frame& F_a_b1,const Frame& F_a_b2,double dt) {
  984. return Twist(
  985. diff(F_a_b1.p,F_a_b2.p,dt),
  986. diff(F_a_b1.M,F_a_b2.M,dt)
  987. );
  988. }
  989. IMETHOD Twist diff(const Twist& a,const Twist& b,double dt) {
  990. return Twist(diff(a.vel,b.vel,dt),diff(a.rot,b.rot,dt));
  991. }
  992. IMETHOD Wrench diff(const Wrench& a,const Wrench& b,double dt) {
  993. return Wrench(
  994. diff(a.force,b.force,dt),
  995. diff(a.torque,b.torque,dt)
  996. );
  997. }
  998. IMETHOD Vector addDelta(const Vector& a,const Vector&da,double dt) {
  999. return a+da*dt;
  1000. }
  1001. IMETHOD Rotation addDelta(const Rotation& a,const Vector&da,double dt) {
  1002. return a*Rot(a.Inverse(da)*dt);
  1003. }
  1004. IMETHOD Frame addDelta(const Frame& a,const Twist& da,double dt) {
  1005. return Frame(
  1006. addDelta(a.M,da.rot,dt),
  1007. addDelta(a.p,da.vel,dt)
  1008. );
  1009. }
  1010. IMETHOD Twist addDelta(const Twist& a,const Twist&da,double dt) {
  1011. return Twist(addDelta(a.vel,da.vel,dt),addDelta(a.rot,da.rot,dt));
  1012. }
  1013. IMETHOD Wrench addDelta(const Wrench& a,const Wrench&da,double dt) {
  1014. return Wrench(addDelta(a.force,da.force,dt),addDelta(a.torque,da.torque,dt));
  1015. }
  1016. /**
  1017. * \brief addDelta operator for displacement rotational velocity.
  1018. *
  1019. * The Vector arguments here represent a displacement rotational velocity. i.e. a rotation
  1020. * around a fixed axis for a certain angle. For this representation you cannot use diff() but
  1021. * have to use diff_displ().
  1022. *
  1023. * \param a : displacement rotational velocity
  1024. * \param da : rotational velocity
  1025. * \return displacement rotational velocity
  1026. *
  1027. * \warning do not confuse displacement rotational velocities and velocities
  1028. * \warning do not confuse displacement twist and twist.
  1029. *
  1030. IMETHOD Vector addDelta_displ(const Vector& a,const Vector&da,double dt) {
  1031. return getRot(addDelta(Rot(a),da,dt));
  1032. }*/
  1033. /**
  1034. * \brief addDelta operator for displacement twist.
  1035. *
  1036. * The Vector arguments here represent a displacement rotational velocity. i.e. a rotation
  1037. * around a fixed axis for a certain angle. For this representation you cannot use diff() but
  1038. * have to use diff_displ().
  1039. *
  1040. * \param a : displacement twist
  1041. * \param da : twist
  1042. * \return displacement twist
  1043. *
  1044. * \warning do not confuse displacement rotational velocities and velocities
  1045. * \warning do not confuse displacement twist and twist.
  1046. *
  1047. IMETHOD Twist addDelta_displ(const Twist& a,const Twist&da,double dt) {
  1048. return Twist(addDelta(a.vel,da.vel,dt),addDelta_displ(a.rot,da.rot,dt));
  1049. }*/
  1050. IMETHOD void random(Vector& a) {
  1051. random(a[0]);
  1052. random(a[1]);
  1053. random(a[2]);
  1054. }
  1055. IMETHOD void random(Twist& a) {
  1056. random(a.rot);
  1057. random(a.vel);
  1058. }
  1059. IMETHOD void random(Wrench& a) {
  1060. random(a.torque);
  1061. random(a.force);
  1062. }
  1063. IMETHOD void random(Rotation& R) {
  1064. double alfa;
  1065. double beta;
  1066. double gamma;
  1067. random(alfa);
  1068. random(beta);
  1069. random(gamma);
  1070. R = Rotation::EulerZYX(alfa,beta,gamma);
  1071. }
  1072. IMETHOD void random(Frame& F) {
  1073. random(F.M);
  1074. random(F.p);
  1075. }
  1076. IMETHOD void posrandom(Vector& a) {
  1077. posrandom(a[0]);
  1078. posrandom(a[1]);
  1079. posrandom(a[2]);
  1080. }
  1081. IMETHOD void posrandom(Twist& a) {
  1082. posrandom(a.rot);
  1083. posrandom(a.vel);
  1084. }
  1085. IMETHOD void posrandom(Wrench& a) {
  1086. posrandom(a.torque);
  1087. posrandom(a.force);
  1088. }
  1089. IMETHOD void posrandom(Rotation& R) {
  1090. double alfa;
  1091. double beta;
  1092. double gamma;
  1093. posrandom(alfa);
  1094. posrandom(beta);
  1095. posrandom(gamma);
  1096. R = Rotation::EulerZYX(alfa,beta,gamma);
  1097. }
  1098. IMETHOD void posrandom(Frame& F) {
  1099. random(F.M);
  1100. random(F.p);
  1101. }
  1102. IMETHOD bool operator==(const Frame& a,const Frame& b ) {
  1103. #ifdef KDL_USE_EQUAL
  1104. return Equal(a,b);
  1105. #else
  1106. return (a.p == b.p &&
  1107. a.M == b.M );
  1108. #endif
  1109. }
  1110. IMETHOD bool operator!=(const Frame& a,const Frame& b) {
  1111. return !operator==(a,b);
  1112. }
  1113. IMETHOD bool operator==(const Vector& a,const Vector& b) {
  1114. #ifdef KDL_USE_EQUAL
  1115. return Equal(a,b);
  1116. #else
  1117. return (a.data[0]==b.data[0]&&
  1118. a.data[1]==b.data[1]&&
  1119. a.data[2]==b.data[2] );
  1120. #endif
  1121. }
  1122. IMETHOD bool operator!=(const Vector& a,const Vector& b) {
  1123. return !operator==(a,b);
  1124. }
  1125. IMETHOD bool operator==(const Twist& a,const Twist& b) {
  1126. #ifdef KDL_USE_EQUAL
  1127. return Equal(a,b);
  1128. #else
  1129. return (a.rot==b.rot &&
  1130. a.vel==b.vel );
  1131. #endif
  1132. }
  1133. IMETHOD bool operator!=(const Twist& a,const Twist& b) {
  1134. return !operator==(a,b);
  1135. }
  1136. IMETHOD bool operator==(const Wrench& a,const Wrench& b ) {
  1137. #ifdef KDL_USE_EQUAL
  1138. return Equal(a,b);
  1139. #else
  1140. return (a.force==b.force &&
  1141. a.torque==b.torque );
  1142. #endif
  1143. }
  1144. IMETHOD bool operator!=(const Wrench& a,const Wrench& b) {
  1145. return !operator==(a,b);
  1146. }
  1147. IMETHOD bool operator!=(const Rotation& a,const Rotation& b) {
  1148. return !operator==(a,b);
  1149. }