Esempio n. 1
0
/* ************************************************************************* */
Pose2 Pose2betweenOptimized(const Pose2& r1, const Pose2& r2,
                            boost::optional<Matrix3&> H1, boost::optional<Matrix3&> H2)
{
    // get cosines and sines from rotation matrices
    const Rot2& R1 = r1.r(), R2 = r2.r();
    double c1=R1.c(), s1=R1.s(), c2=R2.c(), s2=R2.s();

    // Assert that R1 and R2 are normalized
    assert(std::abs(c1*c1 + s1*s1 - 1.0) < 1e-5 && std::abs(c2*c2 + s2*s2 - 1.0) < 1e-5);

    // Calculate delta rotation = between(R1,R2)
    double c = c1 * c2 + s1 * s2, s = -s1 * c2 + c1 * s2;
    Rot2 R(Rot2::atan2(s,c)); // normalizes

    // Calculate delta translation = unrotate(R1, dt);
    Point2 dt = r2.t() - r1.t();
    double x = dt.x(), y = dt.y();
    Point2 t(c1 * x + s1 * y, -s1 * x + c1 * y);

    // FD: This is just -AdjointMap(between(p2,p1)) inlined and re-using above
    if (H1) {
        double dt1 = -s2 * x + c2 * y;
        double dt2 = -c2 * x - s2 * y;
        *H1 = Matrix3();
        (*H1) <<
              -c,  -s,  dt1,
              s,  -c,  dt2,
              0.0, 0.0,-1.0;
    }
    if (H2) *H2 = Matrix3::Identity();

    return Pose2(R,t);
}
Esempio n. 2
0
/* ************************************************************************* */
Rot2 Rot2betweenOptimized(const Rot2& r1, const Rot2& r2) {
  // Same as compose but sign of sin for r1 is reversed
  return Rot2::fromCosSin(r1.c() * r2.c() + r1.s() * r2.s(), -r1.s() * r2.c() + r1.c() * r2.s());
}