-
-
Save alexbw/4990279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import numpy as np | |
import sys | |
sys.path.append('/Users/mattjj/Dropbox/work/datta/renderer') | |
from MouseData import MouseData | |
m = MouseData('/Users/mattjj/Dropbox/work/datta/renderer/data/mouse_mesh_low_poly3.npz') | |
translations = m.joint_translations | |
def inv(E): | |
out = E.copy() | |
out[:-1,:-1] = E[:-1,:-1].T | |
out[:-1,-1] = E[:-1,:-1].T.dot(-E[:-1,-1]) | |
return out | |
out = np.zeros((5,4,4)) | |
out[:,-1,-1] = 1. | |
def Es(angles): | |
cosines = np.cos(angles) | |
sines = np.sin(angles) | |
for idx in range(5): | |
cx, cy, cz = cosines[idx] | |
sx, sy, sz = sines[idx] | |
out[idx,:-1,:] = np.array(( (cy*cz, -cy*sz, -sy , translations[idx,0]), | |
(cx*sz-sx*sy*cz, cx*cz+sx*sy*sz, -sx*cy, translations[idx,1]), | |
(sx*sz+sy*cx*cz, sx*cz-cx*sy*sz, cx*cy, translations[idx,2]), )) | |
return out | |
fixed_Es = Es(m.joint_rotations) | |
fixed_Ms = np.empty((5,4,4)) | |
fixed_Ms[0] = inv(fixed_Es[0]) | |
for idx in range(1,5): | |
# cumulative right-product | |
fixed_Ms[idx] = fixed_Ms[idx-1].dot(inv(fixed_Es[idx])) | |
changed_Ms = np.empty((5,4,4)) | |
def get_Ms(angles): | |
changed_Es = Es(angles) | |
changed_Ms[0] = changed_Es[0] | |
for idx in range(1,5): | |
# cumulative left-product | |
changed_Ms[idx] = changed_Es[idx].dot(changed_Ms[idx-1]) | |
return [fixed_M.dot(changed_M) for fixed_M, changed_M in zip(fixed_Ms, changed_Ms)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment