Thanks for all the information. I have used a number of different methods in the past. I have used both the MomentArmSolver as well as the muscle.computeMomentArm() function, and both worked well.
However for my application I found that it was quicker for me to implement my own routine which basically reimplements the MomentArmSolver but only for the muscles and coordinates of interest to me. I have just changed the method I detailed in my original post to use the "Point Force Directions" of the muscle geometry path as suggested by Ajay. It works well and is quick.
FYI here are some benchmarks. They are VERY rough (acquired via a MATLAB mex function on an old PC) but they provide an interesting comparison:
- 1) Using manual finite difference method = 8.3 s
- 2) Using muscle.computeMomentArm() = 19.9 s
- 3) Using MomentArmSolver = 15.2 s
- 4) Using method in my first post = 0.74 s
- 5) Using latest method with PFDs = 0.80 s
This was using Holzabur's upper limb model, calculating moment arms for 37 muscles over 4 coordinates (148 moment arms).
I think my method for implementing it is much quicker for me as I only calculate the model's coupling matrix once for each coordinate of interest, then reuse it for each of the muscles. Interestingly method 4) where I set the muscle's activation to 1 then 0 and use the difference in the generalized forces is always slightly quicker than method 5).
The majority of the time for methods 4) and 5) is spent calculating the coupling matrix "C" (around 0.57 seconds in this case). I would be very interested if you guys know of any way of making that calculation quicker?
Marc