36 IMETHOD Vector::Vector(
const Vector & arg)
38 data[0] = arg.data[0];
39 data[1] = arg.data[1];
40 data[2] = arg.data[2];
43 IMETHOD Vector::Vector(
double x,
double y,
double z)
45 data[0]=x;data[1]=y;data[2]=z;
49 IMETHOD Vector& Vector::operator =(
const Vector & arg)
51 data[0] = arg.data[0];
52 data[1] = arg.data[1];
53 data[2] = arg.data[2];
60 tmp.data[0] = lhs.data[0]+rhs.data[0];
61 tmp.data[1] = lhs.data[1]+rhs.data[1];
62 tmp.data[2] = lhs.data[2]+rhs.data[2];
69 tmp.data[0] = lhs.data[0]-rhs.data[0];
70 tmp.data[1] = lhs.data[1]-rhs.data[1];
71 tmp.data[2] = lhs.data[2]-rhs.data[2];
75 IMETHOD double Vector::x()
const {
return data[0]; }
76 IMETHOD double Vector::y()
const {
return data[1]; }
77 IMETHOD double Vector::z()
const {
return data[2]; }
79 IMETHOD void Vector::x(
double _x ) { data[0] = _x; }
80 IMETHOD void Vector::y(
double _y ) { data[1] = _y; }
81 IMETHOD void Vector::z(
double _z ) { data[2] = _z; }
86 tmp.data[0] = lhs.data[0]*rhs;
87 tmp.data[1] = lhs.data[1]*rhs;
88 tmp.data[2] = lhs.data[2]*rhs;
95 tmp.data[0] = lhs*rhs.data[0];
96 tmp.data[1] = lhs*rhs.data[1];
97 tmp.data[2] = lhs*rhs.data[2];
104 tmp.data[0] = lhs.data[0]/rhs;
105 tmp.data[1] = lhs.data[1]/rhs;
106 tmp.data[2] = lhs.data[2]/rhs;
114 tmp.data[0] = lhs.data[1]*rhs.data[2]-lhs.data[2]*rhs.data[1];
115 tmp.data[1] = lhs.data[2]*rhs.data[0]-lhs.data[0]*rhs.data[2];
116 tmp.data[2] = lhs.data[0]*rhs.data[1]-lhs.data[1]*rhs.data[0];
120 Vector& Vector::operator +=(
const Vector & arg)
123 data[0]+=arg.data[0];
124 data[1]+=arg.data[1];
125 data[2]+=arg.data[2];
129 Vector& Vector::operator -=(
const Vector & arg)
132 data[0]-=arg.data[0];
133 data[1]-=arg.data[1];
134 data[2]-=arg.data[2];
138 Vector Vector::Zero()
140 return Vector(0,0,0);
143 double Vector::operator()(
int index)
const {
148 double& Vector::operator () (
int index)
160 tmp.force = M*arg.force;
161 tmp.torque = M*arg.torque + p*tmp.force;
165 Wrench Frame::Inverse(
const Wrench& arg)
const 168 tmp.force = M.Inverse(arg.force);
169 tmp.torque = M.Inverse(arg.torque-p*arg.force);
175 Wrench Rotation::Inverse(
const Wrench& arg)
const 177 return Wrench(Inverse(arg.force),Inverse(arg.torque));
180 Twist Rotation::Inverse(
const Twist& arg)
const 182 return Twist(Inverse(arg.vel),Inverse(arg.rot));
185 Wrench Wrench::Zero()
187 return Wrench(Vector::Zero(),Vector::Zero());
191 void Wrench::ReverseSign()
193 torque.ReverseSign();
197 Wrench Wrench::RefPoint(
const Vector& v_base_AB)
const 203 return Wrench(this->force,
204 this->torque+this->force*v_base_AB
209 Wrench& Wrench::operator-=(
const Wrench& arg)
216 Wrench& Wrench::operator+=(
const Wrench& arg)
223 double& Wrench::operator()(
int i)
232 double Wrench::operator()(
int i)
const 244 return Wrench(lhs.force*rhs,lhs.torque*rhs);
249 return Wrench(lhs*rhs.force,lhs*rhs.torque);
254 return Wrench(lhs.force/rhs,lhs.torque/rhs);
260 return Wrench(lhs.force+rhs.force,lhs.torque+rhs.torque);
265 return Wrench(lhs.force-rhs.force,lhs.torque-rhs.torque);
271 return Wrench(-arg.force,-arg.torque);
279 tmp.vel = M*arg.vel+p*tmp.rot;
282 Twist Frame::Inverse(
const Twist& arg)
const 285 tmp.rot = M.Inverse(arg.rot);
286 tmp.vel = M.Inverse(arg.vel-p*arg.rot);
292 return Twist(Vector::Zero(),Vector::Zero());
296 void Twist::ReverseSign()
302 Twist Twist::RefPoint(
const Vector& v_base_AB)
const 309 return Twist(this->vel+this->rot*v_base_AB,this->rot);
312 Twist& Twist::operator-=(
const Twist& arg)
319 Twist& Twist::operator+=(
const Twist& arg)
326 double& Twist::operator()(
int i)
335 double Twist::operator()(
int i)
const 347 return Twist(lhs.vel*rhs,lhs.rot*rhs);
352 return Twist(lhs*rhs.vel,lhs*rhs.rot);
357 return Twist(lhs.vel/rhs,lhs.rot/rhs);
363 return Twist(lhs.vel+rhs.vel,lhs.rot+rhs.rot);
368 return Twist(lhs.vel-rhs.vel,lhs.rot-rhs.rot);
374 return Twist(-arg.vel,-arg.rot);
381 return Twist(lhs.rot*rhs.vel+lhs.vel*rhs.rot,lhs.rot*rhs.rot);
385 return Wrench(lhs.rot*rhs.force,lhs.rot*rhs.torque+lhs.vel*rhs.force);
388 Frame::Frame(
const Rotation & R)
394 Frame::Frame(
const Vector & V)
396 M = Rotation::Identity();
400 Frame::Frame(
const Rotation & R,
const Vector & V)
409 return Frame(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
417 Vector Frame::Inverse(
const Vector& arg)
const 419 return M.Inverse(arg-p);
422 Frame Frame::Inverse()
const 424 return Frame(M.Inverse(),-M.Inverse(p));
428 Frame& Frame::operator =(
const Frame & arg)
435 Frame::Frame(
const Frame & arg) :
440 void Vector::ReverseSign()
452 tmp.data[0]=-arg.data[0];
453 tmp.data[1]=-arg.data[1];
454 tmp.data[2]=-arg.data[2];
458 void Vector::Set2DXY(
const Vector2& v)
466 void Vector::Set2DYZ(
const Vector2& v)
475 void Vector::Set2DZX(
const Vector2& v)
488 double& Rotation::operator()(
int i,
int j) {
493 double Rotation::operator()(
int i,
int j)
const {
498 Rotation::Rotation(
double Xx,
double Yx,
double Zx,
499 double Xy,
double Yy,
double Zy,
500 double Xz,
double Yz,
double Zz)
502 data[0] = Xx;data[1]=Yx;data[2]=Zx;
503 data[3] = Xy;data[4]=Yy;data[5]=Zy;
504 data[6] = Xz;data[7]=Yz;data[8]=Zz;
508 Rotation::Rotation(
const Vector& x,
const Vector& y,
const Vector& z)
510 data[0] = x.data[0];data[3] = x.data[1];data[6] = x.data[2];
511 data[1] = y.data[0];data[4] = y.data[1];data[7] = y.data[2];
512 data[2] = z.data[0];data[5] = z.data[1];data[8] = z.data[2];
515 Rotation::Rotation(
const Rotation& arg) {
517 while (count--) data[count] = arg.data[count];
520 Rotation& Rotation::operator=(
const Rotation& arg) {
522 while (count--) data[count] = arg.data[count];
529 data[0]*v.data[0] + data[1]*v.data[1] + data[2]*v.data[2],
530 data[3]*v.data[0] + data[4]*v.data[1] + data[5]*v.data[2],
531 data[6]*v.data[0] + data[7]*v.data[1] + data[8]*v.data[2]
541 return Twist((*
this)*arg.vel,(*
this)*arg.rot);
549 return Wrench((*
this)*arg.force,(*
this)*arg.torque);
552 Rotation Rotation::Identity() {
553 return Rotation(1,0,0,0,1,0,0,0,1);
556 void Rotation::DoRotX(
double angle)
558 double cs =
cos(angle);
559 double sn =
sin(angle);
561 x1 = cs* (*this)(0,1) + sn* (*
this)(0,2);
562 x2 = cs* (*this)(1,1) + sn* (*
this)(1,2);
563 x3 = cs* (*this)(2,1) + sn* (*
this)(2,2);
564 (*this)(0,2) = -sn* (*
this)(0,1) + cs* (*
this)(0,2);
565 (*this)(1,2) = -sn* (*
this)(1,1) + cs* (*
this)(1,2);
566 (*this)(2,2) = -sn* (*
this)(2,1) + cs* (*
this)(2,2);
572 void Rotation::DoRotY(
double angle)
574 double cs =
cos(angle);
575 double sn =
sin(angle);
577 x1 = cs* (*this)(0,0) - sn* (*
this)(0,2);
578 x2 = cs* (*this)(1,0) - sn* (*
this)(1,2);
579 x3 = cs* (*this)(2,0) - sn* (*
this)(2,2);
580 (*this)(0,2) = sn* (*
this)(0,0) + cs* (*
this)(0,2);
581 (*this)(1,2) = sn* (*
this)(1,0) + cs* (*
this)(1,2);
582 (*this)(2,2) = sn* (*
this)(2,0) + cs* (*
this)(2,2);
588 void Rotation::DoRotZ(
double angle)
590 double cs =
cos(angle);
591 double sn =
sin(angle);
593 x1 = cs* (*this)(0,0) + sn* (*
this)(0,1);
594 x2 = cs* (*this)(1,0) + sn* (*
this)(1,1);
595 x3 = cs* (*this)(2,0) + sn* (*
this)(2,1);
596 (*this)(0,1) = -sn* (*
this)(0,0) + cs* (*
this)(0,1);
597 (*this)(1,1) = -sn* (*
this)(1,0) + cs* (*
this)(1,1);
598 (*this)(2,1) = -sn* (*
this)(2,0) + cs* (*
this)(2,1);
605 Rotation Rotation::RotX(
double angle) {
606 double cs=
cos(angle);
607 double sn=
sin(angle);
608 return Rotation(1,0,0,0,cs,-sn,0,sn,cs);
610 Rotation Rotation::RotY(
double angle) {
611 double cs=
cos(angle);
612 double sn=
sin(angle);
613 return Rotation(cs,0,sn,0,1,0,-sn,0,cs);
615 Rotation Rotation::RotZ(
double angle) {
616 double cs=
cos(angle);
617 double sn=
sin(angle);
618 return Rotation(cs,-sn,0,sn,cs,0,0,0,1);
624 void Frame::Integrate(
const Twist& t_this,
double samplefrequency)
626 double n = t_this.rot.Norm()/samplefrequency;
628 p += M*(t_this.vel/samplefrequency);
632 t_this.vel/samplefrequency
637 Rotation Rotation::Inverse()
const 644 Vector Rotation::Inverse(
const Vector& v)
const {
646 data[0]*v.data[0] + data[3]*v.data[1] + data[6]*v.data[2],
647 data[1]*v.data[0] + data[4]*v.data[1] + data[7]*v.data[2],
648 data[2]*v.data[0] + data[5]*v.data[1] + data[8]*v.data[2]
653 void Rotation::SetInverse()
656 tmp = data[1];data[1]=data[3];data[3]=tmp;
657 tmp = data[2];data[2]=data[6];data[6]=tmp;
658 tmp = data[5];data[5]=data[7];data[7]=tmp;
667 double Frame::operator()(
int i,
int j) {
683 double Frame::operator()(
int i,
int j)
const {
700 Frame Frame::Identity() {
701 return Frame(Rotation::Identity(),Vector::Zero());
707 void Vector::Set2DPlane(
const Frame& F_someframe_XY,
const Vector2& v_XY)
712 tmp_XY.Set2DXY(v_XY);
713 tmp_XY = F_someframe_XY*(tmp_XY);
725 IMETHOD Vector2::Vector2(
const Vector2 & arg)
727 data[0] = arg.data[0];
728 data[1] = arg.data[1];
731 IMETHOD Vector2::Vector2(
double x,
double y)
737 IMETHOD Vector2& Vector2::operator =(
const Vector2 & arg)
739 data[0] = arg.data[0];
740 data[1] = arg.data[1];
747 return Vector2(lhs.data[0]+rhs.data[0],lhs.data[1]+rhs.data[1]);
752 return Vector2(lhs.data[0]-rhs.data[0],lhs.data[1]-rhs.data[1]);
757 return Vector2(lhs.data[0]*rhs,lhs.data[1]*rhs);
762 return Vector2(lhs*rhs.data[0],lhs*rhs.data[1]);
767 return Vector2(lhs.data[0]/rhs,lhs.data[1]/rhs);
770 IMETHOD Vector2& Vector2::operator +=(
const Vector2 & arg)
772 data[0]+=arg.data[0];
773 data[1]+=arg.data[1];
777 IMETHOD Vector2& Vector2::operator -=(
const Vector2 & arg)
779 data[0]-=arg.data[0];
780 data[1]-=arg.data[1];
784 IMETHOD Vector2 Vector2::Zero() {
788 IMETHOD double Vector2::operator()(
int index)
const {
793 IMETHOD double& Vector2::operator () (
int index)
799 IMETHOD double Vector2::x()
const {
return data[0]; }
800 IMETHOD double Vector2::y()
const {
return data[1]; }
802 IMETHOD void Vector2::x(
double _x ) { data[0] = _x; }
803 IMETHOD void Vector2::y(
double _y ) { data[1] = _y; }
806 IMETHOD void Vector2::ReverseSign()
815 return Vector2(-arg.data[0],-arg.data[1]);
819 IMETHOD void Vector2::Set3DXY(
const Vector& v)
825 IMETHOD void Vector2::Set3DYZ(
const Vector& v)
831 IMETHOD void Vector2::Set3DZX(
const Vector& v)
838 IMETHOD void Vector2::Set3DPlane(
const Frame& F_someframe_XY,
const Vector& v_someframe)
842 Vector tmp = F_someframe_XY.Inverse(v_someframe);
847 IMETHOD Rotation2::Rotation2(
const Rotation2& arg) {
851 IMETHOD Rotation2& Rotation2::operator=(
const Rotation2& arg) {
857 return Vector2(v.data[0]*c-v.data[1]*s,v.data[0]*s+v.data[1]*c);
860 IMETHOD double Rotation2::operator()(
int i,
int j)
const {
871 return Rotation2(lhs.c*rhs.c-lhs.s*rhs.s,lhs.s*rhs.c+lhs.c*rhs.s);
874 IMETHOD void Rotation2::SetInverse() {
878 IMETHOD Rotation2 Rotation2::Inverse()
const {
879 return Rotation2(c,-s);
882 IMETHOD Vector2 Rotation2::Inverse(
const Vector2& v)
const {
883 return Vector2(v.data[0]*c+v.data[1]*s,-v.data[0]*s+v.data[1]*c);
886 IMETHOD Rotation2 Rotation2::Identity() {
887 return Rotation2(1,0);
890 IMETHOD void Rotation2::SetIdentity()
896 IMETHOD void Rotation2::SetRot(
double angle) {
897 c=
cos(angle);s=
sin(angle);
901 return Rotation2(
cos(angle),
sin(angle));
904 IMETHOD double Rotation2::GetRot()
const {
912 IMETHOD Frame2::Frame2(
const Rotation2 & R)
918 IMETHOD Frame2::Frame2(
const Vector2 & V)
920 M = Rotation2::Identity();
924 IMETHOD Frame2::Frame2(
const Rotation2 & R,
const Vector2 & V)
932 return Frame2(lhs.M*rhs.M,lhs.M*rhs.p+lhs.p);
940 IMETHOD Vector2 Frame2::Inverse(
const Vector2& arg)
const 942 return M.Inverse(arg-p);
945 IMETHOD void Frame2::SetIdentity()
951 IMETHOD void Frame2::SetInverse()
959 IMETHOD Frame2 Frame2::Inverse()
const 966 IMETHOD Frame2& Frame2::operator =(
const Frame2 & arg)
973 IMETHOD Frame2::Frame2(
const Frame2 & arg) :
978 IMETHOD double Frame2::operator()(
int i,
int j) {
994 IMETHOD double Frame2::operator()(
int i,
int j)
const {
1013 return rhs(0)*lhs(0)+rhs(1)*lhs(1)+rhs(2)*lhs(2);
1017 return dot(lhs.vel,rhs.force)+
dot(lhs.rot,rhs.torque);
1021 return dot(lhs.vel,rhs.force)+
dot(lhs.rot,rhs.torque);
1033 return (
Equal(a.data[0],b.data[0],eps)&&
1034 Equal(a.data[1],b.data[1],eps)&&
1035 Equal(a.data[2],b.data[2],eps) );
1040 return (
Equal(a.p,b.p,eps)&&
1041 Equal(a.M,b.M,eps) );
1045 return (
Equal(a.force,b.force,eps)&&
1046 Equal(a.torque,b.torque,eps) );
1050 return (
Equal(a.rot,b.rot,eps)&&
1051 Equal(a.vel,b.vel,eps) );
1055 return (
Equal(a.data[0],b.data[0],eps)&&
1056 Equal(a.data[1],b.data[1],eps) );
1060 return (
Equal(a.c,b.c,eps) &&
Equal(a.s,b.s,eps) );
1064 return (
Equal(a.p,b.p,eps)&&
1065 Equal(a.M,b.M,eps) );
1081 v = Vector2::Zero();
1112 Vector rotvec = axis_a_b;
1113 double angle = rotvec.Normalize(1E-10);
1114 double ct =
::cos(angle);
1115 double st =
::sin(angle);
1118 ct + vt*rotvec(0)*rotvec(0),
1119 -rotvec(2)*st + vt*rotvec(0)*rotvec(1),
1120 rotvec(1)*st + vt*rotvec(0)*rotvec(2),
1121 rotvec(2)*st + vt*rotvec(1)*rotvec(0),
1122 ct + vt*rotvec(1)*rotvec(1),
1123 -rotvec(0)*st + vt*rotvec(1)*rotvec(2),
1124 -rotvec(1)*st + vt*rotvec(2)*rotvec(0),
1125 rotvec(0)*st + vt*rotvec(2)*rotvec(1),
1126 ct + vt*rotvec(2)*rotvec(2)
1133 IMETHOD Vector
diff(
const Rotation& R_a_b1,
const Rotation& R_a_b2,
double dt) {
1134 Rotation R_b1_b2(R_a_b1.Inverse()*R_a_b2);
1135 return R_a_b1 * R_b1_b2.GetRot() / dt;
1138 IMETHOD Twist
diff(
const Frame& F_a_b1,
const Frame& F_a_b2,
double dt) {
1140 diff(F_a_b1.p,F_a_b2.p,dt),
1141 diff(F_a_b1.M,F_a_b2.M,dt)
1145 return Twist(
diff(a.vel,b.vel,dt),
diff(a.rot,b.rot,dt));
1150 diff(a.force,b.force,dt),
1151 diff(a.torque,b.torque,dt)
1161 return Rot(da*dt)*a;
1173 return Wrench(
addDelta(a.force,da.force,dt),
addDelta(a.torque,da.torque,dt));
1235 R = Rotation::EulerZYX(alfa,beta,gamma);
1264 R = Rotation::EulerZYX(alfa,beta,gamma);
1276 #ifdef KDL_USE_EQUAL 1279 return (a.p == b.p &&
1289 #ifdef KDL_USE_EQUAL 1292 return (a.data[0]==b.data[0]&&
1293 a.data[1]==b.data[1]&&
1294 a.data[2]==b.data[2] );
1303 #ifdef KDL_USE_EQUAL 1306 return (a.rot==b.rot &&
1316 #ifdef KDL_USE_EQUAL 1319 return (a.force==b.force &&
1320 a.torque==b.torque );
1332 #ifdef KDL_USE_EQUAL 1335 return (a.data[0]==b.data[0]&&
1336 a.data[1]==b.data[1] );
IMETHOD Vector operator-(const Vector &lhs, const Vector &rhs)
IMETHOD void posrandom(Vector &a)
IMETHOD bool operator!=(const Frame &a, const Frame &b)
IMETHOD Vector operator+(const Vector &lhs, const Vector &rhs)
IMETHOD void random(Vector &a)
addDelta operator for displacement rotational velocity.
Vector operator*(const Vector &lhs, double rhs)
Vector operator/(const Vector &lhs, double rhs)
IMETHOD bool Equal(const Vector &a, const Vector &b, double eps)
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
IMETHOD double dot(const Vector &lhs, const Vector &rhs)
IMETHOD void SetToZero(Vector &v)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
IMETHOD Rotation Rot(const Vector &axis_a_b)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
IMETHOD Vector addDelta(const Vector &a, const Vector &da, double dt)
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
IMETHOD bool operator==(const Frame &a, const Frame &b)