68 template <
class Precision =
double>
75 SE3_():my_rotation(0,0,0,1),my_translation(0,0,0){}
77 SE3_(
const Precision& x,
const Precision& y,
const Precision& z,
78 const Precision& wx,
const Precision& wy,
const Precision& wz,
const Precision& w)
79 :my_rotation(wx,wy,wz,w),my_translation(x,y,z){}
82 :my_rotation(r),my_translation(t){}
84 template <
typename Scalar>
100 inline SE3_ inverse()
const {
102 return SE3_(rinv, -(rinv*my_translation));
122 inline bool operator <(const SE3_<P>& rhs)
const 143 Precision x,y,z,rx,ry,rz,w;
144 is>>x>>y>>z>>rx>>ry>>rz>>w;
145 rhs=
SE3_(x,y,z,rx,ry,rz,w);
157 r[0]=m[0]; r[1]=m[1]; r[2] =m[2]; my_translation[0] =m[3];
158 r[3]=m[4]; r[4]=m[5]; r[5] =m[6]; my_translation[1] =m[7];
159 r[6]=m[8]; r[7]=m[9]; r[8]=m[10]; my_translation[2] =m[11];
160 my_rotation.fromMatrix(r);
164 void getMatrix(Precision* m)
const 167 my_rotation.getMatrix(r);
169 m[0]=r[0]; m[1]=r[1]; m[2] =r[2]; m[3] =my_translation[0];
170 m[4]=r[3]; m[5]=r[4]; m[6] =r[5]; m[7] =my_translation[1];
171 m[8]=r[6]; m[9]=r[7]; m[10]=r[8]; m[11]=my_translation[2];
175 operator TooN::SE3<Precision>()
177 return TooN::SE3<Precision>(my_rotation,*(TooN::Vector<3,Precision>*)&my_translation);
182 my_rotation.fromMatrixUnsafe(tn.get_rotation());
183 my_translation=*(Vec3*)&tn.get_translation();
187 #ifdef SOPHUS_SE3_HPP 188 operator Sophus::SE3Group<Precision>()
190 assert(
sizeof(Sophus::SE3Group<Precision>) !=
sizeof(*
this));
193 Sophus::SE3Group<Precision> sophusSE3;
194 for(
int i=0;i<7;i++) sophusSE3.data()[i]=((
double*)
this)[i];
199 : my_rotation(sophus.so3()),
200 my_translation(*(Vec3*)&sophus.translation())
208 const auto& l=my_rotation;
209 const auto& t=my_translation;
210 const Precision squared_w = l.w*l.w;
211 const Precision n = sqrt(l.x*l.x+l.y*l.y+l.z*l.z);
224 A_inv = 2./l.w - 2.*(1.0-squared_w)/(l.w*squared_w);
226 Point3_<Precision> p=t-0.5*r.cross(t)+
static_cast<Precision
>(1. / 12.)*r.cross(r.cross(t));
232 if (fabs(l.w)<NEAR_ZERO)
245 A_inv = 2*atan(n/l.w)/n;
250 Point3_<Precision> p=t-0.5*r.cross(t)+(1-theta/(2*tan(0.5*theta)))*a.cross(a.cross(t));
257 template <
typename Scalar>
262 Scalar theta_sq = r.dot(r);
263 Scalar theta = sqrt(theta_sq);
264 Scalar half_theta =
static_cast<Scalar
>(0.5) * theta;
269 if (theta < static_cast<Scalar>(1e-10)) {
270 Scalar theta_po4 = theta_sq * theta_sq;
271 imag_factor =
static_cast<Scalar
>(0.5) -
272 static_cast<Scalar
>(1.0 / 48.0) * theta_sq +
273 static_cast<Scalar
>(1.0 / 3840.0) * theta_po4;
274 real_factor =
static_cast<Scalar
>(1) -
275 static_cast<Scalar>(0.5) * theta_sq +
276 static_cast<Scalar
>(1.0 / 384.0) * theta_po4;
278 Scalar sin_half_theta = sin(half_theta);
279 imag_factor = sin_half_theta / theta;
280 real_factor = cos(half_theta);
283 SO3_<Scalar> R( imag_factor * r.x, imag_factor * r.y,imag_factor * r.z,real_factor);
284 auto t= p+(1-cos(theta))/theta_sq*r.cross(p)+
285 (theta-sin(theta))/(theta_sq*theta)*r.cross(r.cross(p));
289 template <
typename Scalar>
294 Scalar theta_sq = r.dot(r);
295 Scalar theta = sqrt(theta_sq);
296 Scalar half_theta =
static_cast<Scalar
>(0.5) * theta;
301 if (theta < static_cast<Scalar>(1e-10)) {
302 Scalar theta_po4 = theta_sq * theta_sq;
303 imag_factor =
static_cast<Scalar
>(0.5) -
304 static_cast<Scalar
>(1.0 / 48.0) * theta_sq +
305 static_cast<Scalar
>(1.0 / 3840.0) * theta_po4;
306 real_factor =
static_cast<Scalar
>(1) -
307 static_cast<Scalar>(0.5) * theta_sq +
308 static_cast<Scalar
>(1.0 / 384.0) * theta_po4;
311 imag_factor = sin_half_theta / theta;
315 SO3_<Scalar> R( imag_factor * r.x, imag_factor * r.y,imag_factor * r.z,real_factor);
332 SE3_ mul (
const SE3_& rq)
const{
return (*
this)*rq;}
335 std::string toString()
const{std::stringstream sst;sst<<*
this;
return sst.str();}
friend Vec3 operator*(const SE3_< Precision > &lhs, const Vec3 &rhs)
Right-multiply by a Vector.
Definition: SE3.h:129
const Vec3 & get_translation() const
Definition: SE3.h:98
3D rotation represented by the quaternion.
Definition: SO3.h:131
friend std::ostream & operator<<(std::ostream &os, const SE3_ &rhs)
Write an SE3 to a stream.
Definition: SE3.h:135
Vec3 & get_translation()
Returns the translation part of the transformation as a Vector.
Definition: SE3.h:96
const SO3_< Precision > & get_rotation() const
Definition: SE3.h:93
friend std::istream & operator>>(std::istream &is, SE3_ &rhs)
Write an SE3 from a stream.
Definition: SE3.h:142
void fromMatrix(const Precision *m)
R is described as follow, M is a 4*4 Homography matrix |r0 r1 r2| |r3 r4 r5| |r6 r7 r8|...
Definition: SE3.h:154
SE3_ & operator*=(const SE3_< P > &rhs)
Right-multiply by another SE3 (concatenate the two transformations)
Definition: SE3.h:108
SO3_< Precision > & get_rotation()
Returns the rotation part of the transformation as a SO3.
Definition: SE3.h:91
Represent a three-dimensional Euclidean transformation (a rotation and a translation).
Definition: SE3.h:69