ó
s™xTc           @   s™   d  Z  d d l m Z y d d l Z Wn e k
 rE d d l Z n Xd d l m Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d S(   s  Based in part on Roy Featherstone's spatial_v1 matlab code:

  http://axiom.anu.edu.au/~roy/spatial/

  Version 1: January 2008 (latest bug fix: 7 October 2008)

See also: RBDA:
  Rigid Body Dynamics Algorithms.
  Roy Featherstone,
  Springer, New York, 2007.
  ISBN-10: 0387743146
iÿÿÿÿ(   t   divisionN(   t   matrixc   	   %   C   sš   |  \	 } } } } }  } } } } t  j | | | d d d | |  | d d d | | | d d d d d d | | | d d d | |  | d d d | | | f$ ƒ S(   sß   RBDA Tab. 2.2, p. 23:
Spatial coordinate transform (rotation around origin).
Calculates the coordinate transform matrix from A to B coordinates
for spatial motion vectors, in which frame B is rotated relative to
frame A.
  i    (   R   t   sqr(	   t   et   at   bt   ct   dt   ft   gt   ht   i(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   xrot   s    !c      %   C   s‹   |  \ } } } t  j d d d d d d d d d d d d d d d d d d d | | d d d | d | d d d | | d d d d f$ ƒ S(   sü   RBDA Tab. 2.2, p. 23:
Spatial coordinate transform (translation of origin).
Calculates the coordinate transform matrix from A to B coordinates
for spatial motion vectors, in which frame B is translated by an
amount r (3D vector) relative to frame A.
  i   i    (   R   R   (   t   rt   r1t   r2t   r3(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   xtrans$   s    c         C   s(   t  |  j ƒ t |  j j ƒ  |  j ƒ S(   sN   RBDA Eq. 2.28, p. 22:
Conversion of matrix.rt object cb to spatial transform.
(   R   R   R   t	   transposet   t(   t   cb(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   cb_as_spatial_transform4   s    c      %   C   sš   |  \ } } } } } } t  j d | | d d d | d | d d d | | d d d d d | | d | | | d | | d | | | d | | d f$ ƒ S(   s¹   RBDA Eq. 2.31, p. 25:
Spatial cross-product operator (motion).
Calculates the 6x6 matrix such that the expression crm(v)*m is the
cross product of the spatial motion vectors v and m.
  i    (   R   R   (   t   vt   v1t   v2t   v3t   v4t   v5t   v6(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   crm:   s    c         C   s   t  |  ƒ j ƒ  S(   sÑ   RBDA Eq. 2.32, p. 25:
Spatial cross-product operator (force).
Calculates the 6x6 matrix such that the expression crf(v)*f is the
cross product of the spatial motion vector v with the spatial force
vector f.
  (   R   R   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   crfI   s    c         C   s[   t  j | ƒ } t  j | |  | | j ƒ  |  | |  | j ƒ  |  t  j d ƒ f ƒ j ƒ  S(   sø   RBDA Eq. 2.63, p. 33:
Spatial rigid-body inertia from mass, CoM and rotational inertia.
Calculates the spatial inertia matrix of a rigid body from its
mass, centre of mass (3D vector) and rotational inertia (3x3 matrix)
about its centre of mass.
  i   (   R   t   cross_product_matrixR   R   t   identityt   resolve_partitions(   t   mR   R   t   cx(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   mciR   s    c         C   s   d | j  |  | ƒ S(   s   RBDA Eq. 2.67, p. 35g      à?(   t   dot(   t	   i_spatialt	   v_spatial(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   kinetic_energy^   s    (   t   __doc__t
   __future__R    t   scitbxt   ImportErrort   scitbx_matrixR   R   R   R   R   R   R$   R(   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/rigid_body/essence/spatial_lib.pyt   <module>   s     							