Skip to content

Instantly share code, notes, and snippets.

@orangeduck
Created April 4, 2024 23:17
Show Gist options
  • Save orangeduck/e1d70fdbfcdcf327850b7b39a36543c9 to your computer and use it in GitHub Desktop.
Save orangeduck/e1d70fdbfcdcf327850b7b39a36543c9 to your computer and use it in GitHub Desktop.
def quat_from_xform(ts):
return quat_normalize(
torch.where((ts[...,2,2] < 0.0)[...,None],
torch.where((ts[...,0,0] > ts[...,1,1])[...,None],
torch.cat([
(ts[...,2,1]-ts[...,1,2])[...,None],
(1.0 + ts[...,0,0] - ts[...,1,1] - ts[...,2,2])[...,None],
(ts[...,1,0]+ts[...,0,1])[...,None],
(ts[...,0,2]+ts[...,2,0])[...,None]], dim=-1),
torch.cat([
(ts[...,0,2]-ts[...,2,0])[...,None],
(ts[...,1,0]+ts[...,0,1])[...,None],
(1.0 - ts[...,0,0] + ts[...,1,1] - ts[...,2,2])[...,None],
(ts[...,2,1]+ts[...,1,2])[...,None]], dim=-1)),
torch.where((ts[...,0,0] < -ts[...,1,1])[...,None],
torch.cat([
(ts[...,1,0]-ts[...,0,1])[...,None],
(ts[...,0,2]+ts[...,2,0])[...,None],
(ts[...,2,1]+ts[...,1,2])[...,None],
(1.0 - ts[...,0,0] - ts[...,1,1] + ts[...,2,2])[...,None]], dim=-1),
torch.cat([
(1.0 + ts[...,0,0] + ts[...,1,1] + ts[...,2,2])[...,None],
(ts[...,2,1]-ts[...,1,2])[...,None],
(ts[...,0,2]-ts[...,2,0])[...,None],
(ts[...,1,0]-ts[...,0,1])[...,None]], dim=-1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment