This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Interpolation of Affine3f

Tags: None
(comma "," separated)
nicokruithof
Registered Member
Posts
3
Karma
0

Interpolation of Affine3f

Wed Mar 07, 2012 10:51 am
Hello,

What is the fastest way to interpolate Affine transforms (by linearly interpolating the position, rotation and scale independently). Currently we use the following code:
Code: Select all
inline void lerp_decompose(const Affine3f &aff, Vector3f &pos, Quaternionf &rot, Vector3f &scale)
{
    Matrix33f rot_mat, scale_mat;
    aff.computeRotationScaling(&rot_mat, &scale_mat);

    pos = aff.translation();
    rot = Quaternionf(rot_mat);
    scale = scale_mat.diagonal();
}
inline Affine3f lerp_compose(float alpha,
                             const Vector3f &pos0, const Quaternionf &rot0, const Vector3f &scale0,
                             const Vector3f &pos1, const Quaternionf &rot1, const Vector3f &scale1)
{
    float one_minus_alpha = 1-alpha;

    Affine3f result;
    result.fromPositionOrientationScale(
        one_minus_alpha * pos0 + alpha * pos1,
        rot0.slerp(alpha, rot1),
        one_minus_alpha*scale0 + alpha*scale1);

    return result;
}
inline Affine3f lerp(float alpha, const Affine3f &aff0, const Affine3f &aff1)
{
    Vector3f pos0; Quaternionf rot0; Vector3f scale0;
    Vector3f pos1; Quaternionf rot1; Vector3f scale1;
    lerp_decompose(aff0, pos0, rot0, scale0);
    lerp_decompose(aff1, pos1, rot1, scale1);

    return lerp_compose(alpha, pos0, rot0, scale0, pos1, rot1, scale1);
}

Whenever possible we store the decomposed values and only compose the interpolated Affine matrix.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Interpolation of Affine3f

Wed Mar 07, 2012 12:16 pm
Sounds good.

The lerp_decompose step is by far the most expensive one, so it is very important to avoid it as much as you can by storing and using triplets of Quaternion, Scale, and Translation.
nicokruithof
Registered Member
Posts
3
Karma
0

Re: Interpolation of Affine3f

Wed Mar 07, 2012 1:19 pm
Would it be more efficient to store the 3x3 rotation matrices instead of the quaternions because you'll need those in the end in the affine transform?
Or will the slerp function become much more complicated then?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Interpolation of Affine3f

Wed Mar 07, 2012 9:22 pm
slep cannot be easily done a 3x3 rotation matrix. Quaternion is really the best representation for that.

btw, for the affine to quaternion-scale-translation decomposition, if you know that the affine transformation has no shear, then you can simply do:

scale = aff.linear().colwise().norm();
a = aff.linear() * scale.asDiagonal().inverse();

which is reasonably fast compared to the general case.
nicokruithof
Registered Member
Posts
3
Karma
0

Re: Interpolation of Affine3f

Thu Mar 08, 2012 3:10 pm
Ah, yes. That makes sense.

Thanks for helping me out.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]