Code Monkey home page Code Monkey logo

Comments (4)

sherm1 avatar sherm1 commented on May 27, 2024 1

Wikipedia also mentions this in its Slerp entry.
My thought would be that Simbody's Quaternion class should have a q=q1.slerp(f, q2) function that returns a quaternion q some fraction f of the shortest way between q1 and q2. That seems better to me than exposing the non-canonical quaternion.

from simbody.

fcanderson avatar fcanderson commented on May 27, 2024

Thanks for the Wikipedia link. I should have found that!

Blender has a slerp() method just like the one you propose: mathutils.Quaternion.slerp(q2, f). Blender calls that method internally when it interpolates quaternions. There's an important difference though. Blender's slerp() does not pick the "shortest way between q1 and q2", which is what I was stymied by. It sometimes generates quaternions that lie on the long arc between q1 and q2. I therefore took things into my own hands and altered the quaternions I handed to Blender. Hence the origin of the static method that appears in my previous comment.

Even if SimTK::Quaternion_::slerp(f, q2) were available to me, it wouldn't remove the need to call the static method I wrote (or one like it) however. I don't have a way (that I'm aware of) of asking Blender to use SimTK::Quaternion::slerp(f, q2) for the interpolations that Blender performs internally.

Your proposed slerp() sent me back to dig more into Blender's API, thinking Blender MUST have an approach for ensuring short-arc interpolations. Having missed it the first few times I looked through the API again, and I think I've identified the approach. The short arc decision is handled in a method intended to be called prior to the slerp() method. The call is q2.make_compatible(q1), which changes q2 to the form (canonical or non-canonical) that makes the angle between q1 and q2 less than 180°, which is what my static method does.

Since it is so much faster to do in C++, it would still be nice to have the SimTK Slerp method. However, I would want two methods:

/// Return a quaternion, expressed in canonical form, that is some fraction f along the shortest
/// path between this quaternion and a specified quaternion q2.

Quaternion_ Quaternion_::slerp(const RealP& f, const Quaternion_& q2) const {
     // Ensure interpolation with q2 will result in the short arc quaternions
     Quaternion q2short = this->shortArc(q2);
     // Interpolate using *this and q2short
     q = ... {slerp from Wikipedia }
     return q;
}

/// Return a quaternion which, when used in slerp, will yield quaternions on the short arc between
/// this quaternion and a specified quaternion, q2. The returned quaternion will be equal to
/// q2 or -q2 and therefore may be in non-canonical form.

template <class P> Quaternion_<P>
Quaternion_<P>::shortArc(const Quaternion_<P>& q2) const {
    RealP this_dot_q2 = ~(*this) * q2;
    Vec4P q(q2.asVec4());
    if(this_dot_q2 < 0.0) { q = -q; }
    return Quaternion_<P>(q);
}

I'd use the slerp() method when resampling quaternions for different video frame rates and playback speeds. As a last step, I'd use the shortArc() method to express the quaternions in a form that won't require a call to Blender's q2.make_compatible(q1). I can certainly make do without a public shortArc() method, but it would be nice to have.

from simbody.

hwy1992129 avatar hwy1992129 commented on May 27, 2024

Hello, I am working on OpenSim and Blender. I am interested in your work on Simbody and Blender. Could I learn about what you are doing? Thanks.

from simbody.

fcanderson avatar fcanderson commented on May 27, 2024

@hwy1992129 I'd be happy to discuss my activities relating to OpenSim, Simbody, and Blender. It's probably better if you and I interact via the email address associated with my GitHub repositories: [email protected]. Feel free to send me an email, and please tell me more about your interests and activities.

from simbody.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.