I am implementing a simulation that needs to rotate and object based on known angular velocity (assumed constant for simplicity). I followed the ideas given below, pg. 32)


The orientation of the object will be kept in a matrix $R$, angular velocity in $\omega$, a vector.

The book says I can compute $\dot{R}$ by taking the skew-symmetric form of $\omega$ and multiply with each column of $R$. This is all fine, but how do I interface that with an numerical integrator, such as scipy.odeint? First of all this sofware expects flat vectors, do I flatten each $\tilde \omega \cdot R_i$ where $R_i$ is the $i$th column and $\tilde \omega$ is the skew-symmetric matrix of $\omega$?

  • 2
    $\begingroup$ The .reshape and .flatten methods are a useful pair for the transformation from flat array to more structured data and back. Slicing and .concatenate are also useful. $\endgroup$ Jul 1 at 15:24
  • $\begingroup$ Can odeint work with piecemeal $\dot{R}$ components? $\endgroup$
    – BBSysDyn
    Jul 1 at 15:39
  • 1
    $\begingroup$ There is an odeintw package that provides a wrapper for some cases. odeint only works with flat arrays, how the components are interpreted has to be established inside the derivatives function. $\endgroup$ Jul 1 at 17:01

The code below seemed to work. As example used this Torus shape and integrated a basic rotation equation,

from scipy.integrate import odeint
from stl import mesh

def skew(a):
   return np.array([[0,-a[2],a[1]],[a[2],0,-a[0]],[-a[1],a[0],0]])

your_mesh = mesh.Mesh.from_file('torus.stl')
prop = your_mesh.get_mass_properties()
R0 = np.eye(3,3)
omega = np.array([0.0,1.0,0.0])
skew_omega = skew(omega)
def rhs(u,t):   
   R1x,R1y,R1z,R2x,R2y,R2z,R3x,R3y,R3z = u
   R = np.array([R1x,R1y,R1z,R2x,R2y,R2z,R3x,R3y,R3z])
   R = R.reshape((3,3)).T
   res = np.dot(skew_omega, R)
   return list(res.T.flatten())

STEPS = 20
t=np.linspace(0.0, 3.0, STEPS)
R0 = np.eye(3,3)
u0 = R0.flatten()
  • $\begingroup$ Can you write down the differential equations involved? $\endgroup$
    – nicoguaro
    Jul 5 at 15:34
  • $\begingroup$ $\frac{d R}{d t} = \tilde \omega \cdot R$. See the Pixar book link I shared for details. $\endgroup$
    – BBSysDyn
    Jul 5 at 17:10
  • $\begingroup$ I mean that you could add your details to your question/answer. $\endgroup$
    – nicoguaro
    Jul 5 at 17:12
  • $\begingroup$ If you upvote I might $\endgroup$
    – BBSysDyn
    Jul 5 at 17:13
  • 2
    $\begingroup$ That's not how this site works. I am trying to improve the quality of the questions and answers here. That is, in part, my role as a moderator. $\endgroup$
    – nicoguaro
    Jul 5 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.