Solving ODEs, Rotations, Angular Velocity, Euler Angles

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)

https://graphics.stanford.edu/courses/cs448b-00-winter/papers/phys_model.pdf

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$$?

• 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. Jul 1 at 15:24
• Can odeint work with piecemeal $\dot{R}$ components? Jul 1 at 15:39
• 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. Jul 1 at 17:01

1 Answer

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()
u1=odeint(rhs,list(u0),t)

• Can you write down the differential equations involved? Jul 5 at 15:34
• $\frac{d R}{d t} = \tilde \omega \cdot R$. See the Pixar book link I shared for details. Jul 5 at 17:10
• I mean that you could add your details to your question/answer. Jul 5 at 17:12
• If you upvote I might Jul 5 at 17:13
• 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. Jul 5 at 18:05