ó
ņ4[c           @  sš  d  Z  d d l m Z m Z d d l Z d d l Z d Z d Z d] Z d   Z	 d   Z
 d   Z d	   Z d
   Z d d  Z d   Z d d d  Z d   Z d d e d  Z e d  Z e d  Z d   Z d   Z d   Z d d d d d d  Z d   Z e e e d  Z e e d  Z d d  Z d d  Z  d d  Z! d d  Z" d   Z# d   Z$ e d   Z% d!   Z& d"   Z' d#   Z( d$   Z) d%   Z* d& e d'  Z+ d d(  Z, d d)  Z- d* e. f d+     YZ/ d,   Z0 d-   Z1 d.   Z2 e j3 e4  j5 d/ Z6 d0 d1 d& d0 g Z7 i d^ d 6d_ d2 6d` d3 6da d4 6db d5 6dc d6 6dd d7 6de d8 6df d9 6dg d: 6dh d; 6di d< 6dj d= 6dk d> 6dl d? 6dm d@ 6dn dA 6do dB 6dp dC 6dq dD 6dr dE 6ds dF 6dt dG 6du dH 6Z8 e9 dI   e8 j:   D  Z; d d dJ  Z< d d dK  Z= dL   Z> d& dM  Z? e d& dN  Z@ dO   ZA dP   ZB dQ   ZC dR   ZD d e dS dT dU  ZE eE dV  eF dW k rģd d lG ZG d d lH ZH y  e jI dX e dY dZ d[ d\  Wn' eJ k
 rŽe jI dX e dY dZ  n XeG jK   n  d S(v   sR  Homogeneous Transformation Matrices and Quaternions.

A library for calculating 4x4 matrices for translating, rotating, reflecting,
scaling, shearing, projecting, orthogonalizing, and superimposing arrays of
3D homogeneous coordinates as well as for converting between rotation matrices,
Euler angles, and quaternions. Also includes an Arcball control object and
functions to decompose transformation matrices.

:Author:
  `Christoph Gohlke <https://www.lfd.uci.edu/~gohlke/>`_

:Organization:
  Laboratory for Fluorescence Dynamics, University of California, Irvine

:Version: 2018.02.08

Requirements
------------
* `CPython 2.7 or 3.6 <http://www.python.org>`_
* `Numpy 1.13 <http://www.numpy.org>`_
* `Transformations.c 2018.02.08 <https://www.lfd.uci.edu/~gohlke/>`_
  (recommended for speedup of some functions)

Notes
-----
The API is not stable yet and is expected to change between revisions.

This Python code is not optimized for speed. Refer to the transformations.c
module for a faster implementation of some functions.

Documentation in HTML format can be generated with epydoc.

Matrices (M) can be inverted using numpy.linalg.inv(M), be concatenated using
numpy.dot(M0, M1), or transform homogeneous coordinate arrays (v) using
numpy.dot(M, v) for shape (4, \*) column vectors, respectively
numpy.dot(v, M.T) for shape (\*, 4) row vectors ("array of points").

This module follows the "column vectors on the right" and "row major storage"
(C contiguous) conventions. The translation components are in the right column
of the transformation matrix, i.e. M[:3, 3].
The transpose of the transformation matrices may have to be used to interface
with other graphics systems, e.g. with OpenGL's glMultMatrixd(). See also [16].

Calculations are carried out with numpy.float64 precision.

Vector, point, quaternion, and matrix function arguments are expected to be
"array like", i.e. tuple, list, or numpy arrays.

Return types are numpy arrays unless specified otherwise.

Angles are in radians unless specified otherwise.

Quaternions w+ix+jy+kz are represented as [w, x, y, z].

A triple of Euler angles can be applied/interpreted in 24 ways, which can
be specified using a 4 character string or encoded 4-tuple:

  *Axes 4-string*: e.g. 'sxyz' or 'ryxy'

  - first character : rotations are applied to 's'tatic or 'r'otating frame
  - remaining characters : successive rotation axis 'x', 'y', or 'z'

  *Axes 4-tuple*: e.g. (0, 0, 0, 0) or (1, 1, 1, 1)

  - inner axis: code of axis ('x':0, 'y':1, 'z':2) of rightmost matrix.
  - parity : even (0) if inner axis 'x' is followed by 'y', 'y' is followed
    by 'z', or 'z' is followed by 'x'. Otherwise odd (1).
  - repetition : first and last axis are same (1) or different (0).
  - frame : rotations are applied to static (0) or rotating (1) frame.

Other Python packages and modules for 3D transformations and quaternions:

* `Transforms3d <https://pypi.python.org/pypi/transforms3d>`_
   includes most code of this module.
* `Blender.mathutils <http://www.blender.org/api/blender_python_api>`_
* `numpy-dtypes <https://github.com/numpy/numpy-dtypes>`_

References
----------
(1)  Matrices and transformations. Ronald Goldman.
     In "Graphics Gems I", pp 472-475. Morgan Kaufmann, 1990.
(2)  More matrices and transformations: shear and pseudo-perspective.
     Ronald Goldman. In "Graphics Gems II", pp 320-323. Morgan Kaufmann, 1991.
(3)  Decomposing a matrix into simple transformations. Spencer Thomas.
     In "Graphics Gems II", pp 320-323. Morgan Kaufmann, 1991.
(4)  Recovering the data from the transformation matrix. Ronald Goldman.
     In "Graphics Gems II", pp 324-331. Morgan Kaufmann, 1991.
(5)  Euler angle conversion. Ken Shoemake.
     In "Graphics Gems IV", pp 222-229. Morgan Kaufmann, 1994.
(6)  Arcball rotation control. Ken Shoemake.
     In "Graphics Gems IV", pp 175-192. Morgan Kaufmann, 1994.
(7)  Representing attitude: Euler angles, unit quaternions, and rotation
     vectors. James Diebel. 2006.
(8)  A discussion of the solution for the best rotation to relate two sets
     of vectors. W Kabsch. Acta Cryst. 1978. A34, 827-828.
(9)  Closed-form solution of absolute orientation using unit quaternions.
     BKP Horn. J Opt Soc Am A. 1987. 4(4):629-642.
(10) Quaternions. Ken Shoemake.
     http://www.sfu.ca/~jwa3/cmpt461/files/quatut.pdf
(11) From quaternion to matrix and back. JMP van Waveren. 2005.
     http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm
(12) Uniform random rotations. Ken Shoemake.
     In "Graphics Gems III", pp 124-132. Morgan Kaufmann, 1992.
(13) Quaternion in molecular modeling. CFF Karney.
     J Mol Graph Mod, 25(5):595-604
(14) New method for extracting the quaternion from a rotation matrix.
     Itzhack Y Bar-Itzhack, J Guid Contr Dynam. 2000. 23(6): 1085-1087.
(15) Multiple View Geometry in Computer Vision. Hartley and Zissermann.
     Cambridge University Press; 2nd Ed. 2004. Chapter 4, Algorithm 4.7, p 130.
(16) Column Vectors vs. Row Vectors.
     http://steve.hollasch.net/cgindex/math/matrix/column-vec.html

Examples
--------
>>> alpha, beta, gamma = 0.123, -1.234, 2.345
>>> origin, xaxis, yaxis, zaxis = [0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]
>>> I = identity_matrix()
>>> Rx = rotation_matrix(alpha, xaxis)
>>> Ry = rotation_matrix(beta, yaxis)
>>> Rz = rotation_matrix(gamma, zaxis)
>>> R = concatenate_matrices(Rx, Ry, Rz)
>>> euler = euler_from_matrix(R, 'rxyz')
>>> numpy.allclose([alpha, beta, gamma], euler)
True
>>> Re = euler_matrix(alpha, beta, gamma, 'rxyz')
>>> is_same_transform(R, Re)
True
>>> al, be, ga = euler_from_matrix(Re, 'rxyz')
>>> is_same_transform(Re, euler_matrix(al, be, ga, 'rxyz'))
True
>>> qx = quaternion_about_axis(alpha, xaxis)
>>> qy = quaternion_about_axis(beta, yaxis)
>>> qz = quaternion_about_axis(gamma, zaxis)
>>> q = quaternion_multiply(qx, qy)
>>> q = quaternion_multiply(q, qz)
>>> Rq = quaternion_matrix(q)
>>> is_same_transform(R, Rq)
True
>>> S = scale_matrix(1.23, origin)
>>> T = translation_matrix([1, 2, 3])
>>> Z = shear_matrix(beta, xaxis, origin, zaxis)
>>> R = random_rotation_matrix(numpy.random.rand(3))
>>> M = concatenate_matrices(T, R, Z, S)
>>> scale, shear, angles, trans, persp = decompose_matrix(M)
>>> numpy.allclose(scale, 1.23)
True
>>> numpy.allclose(trans, [1, 2, 3])
True
>>> numpy.allclose(shear, [0, math.tan(beta), 0])
True
>>> is_same_transform(R, euler_matrix(axes='sxyz', *angles))
True
>>> M1 = compose_matrix(scale, shear, angles, trans, persp)
>>> is_same_transform(M, M1)
True
>>> v0, v1 = random_vector(3), random_vector(3)
>>> M = rotation_matrix(angle_between_vectors(v0, v1), vector_product(v0, v1))
>>> v2 = numpy.dot(v0, M[:3,:3].T)
>>> numpy.allclose(unit_vector(v1), unit_vector(v2))
True

i’’’’(   t   divisiont   print_functionNs
   2018.02.08s   restructuredtext enc           C  s   t  j d  S(   sć   Return 4x4 identity/unit matrix.

    >>> I = identity_matrix()
    >>> numpy.allclose(I, numpy.dot(I, I))
    True
    >>> numpy.sum(I), numpy.trace(I)
    (4.0, 4.0)
    >>> numpy.allclose(I, numpy.identity(4))
    True

    i   (   t   numpyt   identity(    (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   identity_matrixĻ   s    c         C  s-   t  j d  } |  d  | d d  d f <| S(   s    Return matrix to translate by direction vector.

    >>> v = numpy.random.random(3) - 0.5
    >>> numpy.allclose(v, translation_matrix(v)[:3, 3])
    True

    i   i   N(   R   R   (   t	   directiont   M(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   translation_matrixŽ   s    c         C  s)   t  j |  d t d d  d f j   S(   sČ   Return translation vector from translation matrix.

    >>> v0 = numpy.random.random(3) - 0.5
    >>> v1 = translation_from_matrix(translation_matrix(v0))
    >>> numpy.allclose(v0, v1)
    True

    t   copyNi   (   R   t   arrayt   FalseR   (   t   matrix(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   translation_from_matrixė   s    	c         C  s   t  | d   } t j d  } | d d  d d  f c d t j | |  8<d t j |  d  |  | | d d  d f <| S(   sĻ  Return matrix to mirror at plane defined by point and normal vector.

    >>> v0 = numpy.random.random(4) - 0.5
    >>> v0[3] = 1.
    >>> v1 = numpy.random.random(3) - 0.5
    >>> R = reflection_matrix(v0, v1)
    >>> numpy.allclose(2, numpy.trace(R))
    True
    >>> numpy.allclose(v0, numpy.dot(R, v0))
    True
    >>> v2 = v0.copy()
    >>> v2[:3] += v1
    >>> v3 = v0.copy()
    >>> v2[:3] -= v1
    >>> numpy.allclose(v2, numpy.dot(R, v3))
    True

    i   i   Ng       @(   t   unit_vectorR   R   t   outert   dot(   t   pointt   normalR   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   reflection_matrix÷   s
    2.c         C  s\  t  j |  d t  j d t } t  j j | d d  d d  f  \ } } t  j t t  j |  d  d k   d } t	 |  s t
 d   n  t  j | d d  | d f  j   } t  j j |  \ } } t  j t t  j |  d  d k   d } t	 |  st
 d	   n  t  j | d d  | d
 f  j   } | | d } | | f S(   sQ  Return mirror plane point and normal vector from reflection matrix.

    >>> v0 = numpy.random.random(3) - 0.5
    >>> v1 = numpy.random.random(3) - 0.5
    >>> M0 = reflection_matrix(v0, v1)
    >>> point, normal = reflection_from_matrix(M0)
    >>> M1 = reflection_matrix(point, normal)
    >>> is_same_transform(M0, M1)
    True

    t   dtypeR   Ni   g      š?g:0āyE>i    s2   no unit eigenvector corresponding to eigenvalue -1s1   no unit eigenvector corresponding to eigenvalue 1i’’’’(   R   R	   t   float64R
   t   linalgt   eigt   wheret   abst   realt   lent
   ValueErrort   squeeze(   R   R   t   wt   Vt   iR   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   reflection_from_matrix  s    .,),)c         C  sF  t  j |   } t  j |   } t | d   } t j | | | g  } | t j | |  d | 7} | | 9} | t j d | d | d g | d d | d g | d | d d g g  7} t j d  } | | d d  d d  f <| d k	 rBt j | d  d	 t j
 d
 t } | t j | |  | d d  d f <n  | S(   s  Return matrix to rotate about axis defined by point and direction.

    >>> R = rotation_matrix(math.pi/2, [0, 0, 1], [1, 0, 0])
    >>> numpy.allclose(numpy.dot(R, [0, 0, 0, 1]), [1, -1, 0, 1])
    True
    >>> angle = (random.random() - 0.5) * (2*math.pi)
    >>> direc = numpy.random.random(3) - 0.5
    >>> point = numpy.random.random(3) - 0.5
    >>> R0 = rotation_matrix(angle, direc, point)
    >>> R1 = rotation_matrix(angle-2*math.pi, direc, point)
    >>> is_same_transform(R0, R1)
    True
    >>> R0 = rotation_matrix(angle, direc, point)
    >>> R1 = rotation_matrix(-angle, -direc, point)
    >>> is_same_transform(R0, R1)
    True
    >>> I = numpy.identity(4, numpy.float64)
    >>> numpy.allclose(I, rotation_matrix(math.pi*2, direc))
    True
    >>> numpy.allclose(2, numpy.trace(rotation_matrix(math.pi/2,
    ...                                               direc, point)))
    True

    i   g      š?g        i   i   i    i   NR   R   (   t   matht   sint   cosR   R   t   diagR   R	   R   t   NoneR   R
   R   (   t   angleR   R   t   sinat   cosat   RR   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   rotation_matrix.  s    
")c         C  sA  t  j |  d t  j d t } | d d  d d  f } t  j j | j  \ } } t  j t t  j	 |  d  d k   d } t
 |  s t d   n  t  j	 | d d  | d	 f  j   } t  j j |  \ } } t  j t t  j	 |  d  d k   d } t
 |  s$t d   n  t  j	 | d d  | d	 f  j   } | | d } t  j |  d d
 }	 t | d  d k rµ| d |	 d | d | d | d }
 nm t | d  d k rų| d |	 d | d | d | d }
 n* | d |	 d | d | d | d }
 t j |
 |	  } | | | f S(   s  Return rotation angle and axis from rotation matrix.

    >>> angle = (random.random() - 0.5) * (2*math.pi)
    >>> direc = numpy.random.random(3) - 0.5
    >>> point = numpy.random.random(3) - 0.5
    >>> R0 = rotation_matrix(angle, direc, point)
    >>> angle, direc, point = rotation_from_matrix(R0)
    >>> R1 = rotation_matrix(angle, direc, point)
    >>> is_same_transform(R0, R1)
    True

    R   R   Ni   g      š?g:0āyE>i    s1   no unit eigenvector corresponding to eigenvalue 1i’’’’g       @i   i   (   i   i    (   i    i   (   i   i   (   R   R	   R   R
   R   R   t   TR   R   R   R   R   R   t   traceR!   t   atan2(   R   R)   t   R33R   t   WR   R   t   QR   R(   R'   R&   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   rotation_from_matrixZ  s*    ,),)--*c         C  s  | d k rs t j |  |  |  d g  } | d k	 r| d  | d d  d f <| d d  d f c d |  9<qn t | d   } d |  }  t j d  } | d d  d d  f c |  t j | |  8<| d k	 r|  t j | d  |  | | d d  d f <n  | S(   sš  Return matrix to scale by factor around origin in direction.

    Use factor -1 for point symmetry.

    >>> v = (numpy.random.rand(4, 5) - 0.5) * 20
    >>> v[3] = 1
    >>> S = scale_matrix(-1.234)
    >>> numpy.allclose(numpy.dot(S, v)[:3], -1.234*v[:3])
    True
    >>> factor = random.random() * 10 - 5
    >>> origin = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> S = scale_matrix(factor, origin)
    >>> S = scale_matrix(factor, origin, direct)

    g      š?i   Ni   (   R%   R   R$   R   R   R   R   (   t   factort   originR   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   scale_matrix  s    &
21c   	      C  s  t  j |  d t  j d t } | d d  d d  f } t  j |  d } y t  j j |  \ } } t  j t t  j	 |  |  d k   d d } t  j	 | d d  | f  j
   } | t |  } Wn% t k
 rõ | d d } d } n Xt  j j |  \ } } t  j t t  j	 |  d	  d k   d } t |  sUt d
   n  t  j	 | d d  | d f  j
   } | | d } | | | f S(   s]  Return scaling factor, origin and direction from scaling matrix.

    >>> factor = random.random() * 10 - 5
    >>> origin = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> S0 = scale_matrix(factor, origin)
    >>> factor, origin, direction = scale_from_matrix(S0)
    >>> S1 = scale_matrix(factor, origin, direction)
    >>> is_same_transform(S0, S1)
    True
    >>> S0 = scale_matrix(factor, origin, direct)
    >>> factor, origin, direction = scale_from_matrix(S0)
    >>> S1 = scale_matrix(factor, origin, direction)
    >>> is_same_transform(S0, S1)
    True

    R   R   Ni   g       @g:0āyE>i    g      @g      š?s,   no eigenvector corresponding to eigenvalue 1i’’’’(   R   R	   R   R
   R,   R   R   R   R   R   R   t   vector_normt
   IndexErrorR%   R   R   (	   R   R   t   M33R2   R   R   R   R   R3   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   scale_from_matrix¤  s$    0%
,)c         C  su  t  j d  } t  j |  d  d t  j d t }  t | d   } | d k	 r~t  j | d  d t  j d t } t  j | |  |  | d	 <| d
 <| d <| d d  d d  f c t  j | |  8<| r(| d d  d d  f c t  j | |  8<t  j |  |  | | | d d  d f <n& t  j |  |  | | d d  d f <| | d d d  f <t  j | |  | d <nó | d k	 rt  j | d  d t  j d t } t  j | |  } | d d  d d  f c t  j | |  | 8<| t  j |  |  | | d d  d f <nT | d d  d d  f c t  j | |  8<t  j |  |  | | d d  d f <| S(   s  Return matrix to project onto plane defined by point and normal.

    Using either perspective point, projection direction, or none of both.

    If pseudo is True, perspective projections will preserve relative depth
    such that Perspective = dot(Orthogonal, PseudoPerspective).

    >>> P = projection_matrix([0, 0, 0], [1, 0, 0])
    >>> numpy.allclose(P[1:, 1:], numpy.identity(4)[1:, 1:])
    True
    >>> point = numpy.random.random(3) - 0.5
    >>> normal = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> persp = numpy.random.random(3) - 0.5
    >>> P0 = projection_matrix(point, normal)
    >>> P1 = projection_matrix(point, normal, direction=direct)
    >>> P2 = projection_matrix(point, normal, perspective=persp)
    >>> P3 = projection_matrix(point, normal, perspective=persp, pseudo=True)
    >>> is_same_transform(P2, numpy.dot(P0, P3))
    True
    >>> P = projection_matrix([3, 0, 0], [1, 1, 0], [1, 0, 0])
    >>> v0 = (numpy.random.rand(4, 5) - 0.5) * 20
    >>> v0[3] = 1
    >>> v1 = numpy.dot(P, v0)
    >>> numpy.allclose(v1[1], v0[1])
    True
    >>> numpy.allclose(v1[0], 3-v1[1])
    True

    i   i   R   R   i    i   i   N(   i    i    (   i   i   (   i   i   (   i   i   (	   R   R   R	   R   R
   R   R%   R   R   (   R   R   R   t   perspectivet   pseudoR   t   scale(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   projection_matrixĶ  s,     "	*..-&"2-.&c         C  sņ  t  j |  d t  j d t } | d d  d d  f } t  j j |  \ } } t  j t t  j |  d  d k   d } | rt	 |  rt  j | d d  | d f  j
   } | | d } t  j j |  \ } } t  j t t  j |   d k   d } t	 |  s#t d	   n  t  j | d d  | d f  j
   } | t |  } t  j j | j  \ } } t  j t t  j |   d k   d } t	 |  r÷t  j | d d  | d f  j
   }	 |	 t |	  }	 | |	 | d t f S| | d d t f Snį t  j t t  j |   d k  d } t	 |  sPt d
   n  t  j | d d  | d f  j
   } | | d } | d d d  f }	 | d d  d f t  j | d  |	  }
 | rŪ|
 |	 8}
 n  | |	 d |
 | f Sd S(   s  Return projection plane and perspective point from projection matrix.

    Return values are same as arguments for projection_matrix function:
    point, normal, direction, perspective, and pseudo.

    >>> point = numpy.random.random(3) - 0.5
    >>> normal = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> persp = numpy.random.random(3) - 0.5
    >>> P0 = projection_matrix(point, normal)
    >>> result = projection_from_matrix(P0)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True
    >>> P0 = projection_matrix(point, normal, direct)
    >>> result = projection_from_matrix(P0)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True
    >>> P0 = projection_matrix(point, normal, perspective=persp, pseudo=False)
    >>> result = projection_from_matrix(P0, pseudo=False)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True
    >>> P0 = projection_matrix(point, normal, perspective=persp, pseudo=True)
    >>> result = projection_from_matrix(P0, pseudo=True)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True

    R   R   Ni   g      š?g:0āyE>i    i’’’’s,   no eigenvector corresponding to eigenvalue 0s0   no eigenvector not corresponding to eigenvalue 0(   R   R	   R   R
   R   R   R   R   R   R   R   R   R5   R+   R%   R   (   R   R:   R   R7   R   R   R   R   R   R   R9   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   projection_from_matrix  s>     ,)()()()*c   	      C  sn  |  | k s$ | | k s$ | | k r3 t  d   n  | rć | t k rT t  d   n  d | } | |  | d | |  | |  d g d | | | | | | | d g d d | | | | | | | | g d d d d g g } n~ d | |  d d | |  |  | g d d | | d | | | | g d d d | | | | | | g d d d d g g } t j |  S(   sź  Return matrix to obtain normalized device coordinates from frustum.

    The frustum bounds are axis-aligned along x (left, right),
    y (bottom, top) and z (near, far).

    Normalized device coordinates are in range [-1, 1] if coordinates are
    inside the frustum.

    If perspective is True the frustum is a truncated pyramid with the
    perspective point at origin and direction along z axis, otherwise an
    orthographic canonical view volume (a box).

    Homogeneous coordinates transformed by the perspective clip matrix
    need to be dehomogenized (divided by w coordinate).

    >>> frustum = numpy.random.rand(6)
    >>> frustum[1] += frustum[0]
    >>> frustum[3] += frustum[2]
    >>> frustum[5] += frustum[4]
    >>> M = clip_matrix(perspective=False, *frustum)
    >>> numpy.dot(M, [frustum[0], frustum[2], frustum[4], 1])
    array([-1., -1., -1.,  1.])
    >>> numpy.dot(M, [frustum[1], frustum[3], frustum[5], 1])
    array([ 1.,  1.,  1.,  1.])
    >>> M = clip_matrix(perspective=True, *frustum)
    >>> v = numpy.dot(M, [frustum[0], frustum[2], frustum[4], 1])
    >>> v / v[3]
    array([-1., -1., -1.,  1.])
    >>> v = numpy.dot(M, [frustum[1], frustum[3], frustum[4], 1])
    >>> v / v[3]
    array([ 1.,  1., -1.,  1.])

    s   invalid frustums   invalid frustum: near <= 0g       @g        g      šæg      š?(   R   t   _EPSR   R	   (	   t   leftt   rightt   bottomt   topt   neart   farR9   t   tR   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   clip_matrixT  s    "$
##'###c         C  sŠ   t  | d   } t  | d   } t t j | |   d k rM t d   n  t j |   }  t j d  } | d d  d d  f c |  t j | |  7<|  t j | d  |  | | d d  d f <| S(   s  Return matrix to shear by angle along direction vector on shear plane.

    The shear plane is defined by a point and normal vector. The direction
    vector must be orthogonal to the plane's normal vector.

    A point P is transformed by the shear matrix into P" such that
    the vector P-P" is parallel to the direction vector and its extent is
    given by the angle of P-P'-P", where P' is the orthogonal projection
    of P onto the shear plane.

    >>> angle = (random.random() - 0.5) * 4*math.pi
    >>> direct = numpy.random.random(3) - 0.5
    >>> point = numpy.random.random(3) - 0.5
    >>> normal = numpy.cross(direct, numpy.random.random(3))
    >>> S = shear_matrix(angle, direct, point, normal)
    >>> numpy.allclose(1, numpy.linalg.det(S))
    True

    i   gķµ ÷Ę°>s/   direction and normal vectors are not orthogonali   N(	   R   R   R   R   R   R!   t   tanR   R   (   R&   R   R   R   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   shear_matrix  s    2/c         C  s&  t  j |  d t  j d t } | d d  d d  f } t  j j |  \ } } t  j t t  j |  d  d k   d } t	 |  d k  r£ t
 d	 |   n  t  j | d d  | f  j   j } d
 } x^ d d d f D]M \ } } t  j | | | |  }	 t |	  } | | k rį | } |	 }
 qį qį W|
 | }
 t  j | t  j d  |
  } t |  } | | } t j |  } t  j j |  \ } } t  j t t  j |  d  d k   d } t	 |  sßt
 d   n  t  j | d d  | d f  j   } | | d } | | | |
 f S(   så  Return shear angle, direction and plane from shear matrix.

    >>> angle = (random.random() - 0.5) * 4*math.pi
    >>> direct = numpy.random.random(3) - 0.5
    >>> point = numpy.random.random(3) - 0.5
    >>> normal = numpy.cross(direct, numpy.random.random(3))
    >>> S0 = shear_matrix(angle, direct, point, normal)
    >>> angle, direct, point, normal = shear_from_matrix(S0)
    >>> S1 = shear_matrix(angle, direct, point, normal)
    >>> is_same_transform(S0, S1)
    True

    R   R   Ni   g      š?g-Cėā6?i    i   s/   no two linear independent eigenvectors found %sg      šæi   g:0āyE>s,   no eigenvector corresponding to eigenvalue 1i’’’’(   i    i   (   i    i   (   i   i   (   R   R	   R   R
   R   R   R   R   R   R   R   R   R+   t   crossR5   R   R   R!   t   atan(   R   R   R7   R   R   R   t   lenormt   i0t   i1t   nR   R   R&   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   shear_from_matrix§  s4    ,(

,)c   	      C  sģ  t  j |  d t  j d t j } t | d  t k  rF t d   n  | | d } | j   } d | d d  d f <t  j	 j
 |  s t d   n  t  j d  } d d d g } d d d g } t t | d d  d f  t k  r6t  j | d d  d f t  j	 j | j   } d | d d  d f <n t  j d d d d g  } | d d d  f j   } d | d d d  f <| d d  d d  f j   } t | d	  | d	 <| d	 c | d	 <t  j | d	 | d
  | d	 <| d
 c | d	 | d	 8<t | d
  | d
 <| d
 c | d
 <| d	 c | d
 <t  j | d	 | d  | d
 <| d c | d	 | d
 8<t  j | d
 | d  | d <| d c | d
 | d 8<t | d  | d <| d c | d <| d
 c | d )t  j | d	 t  j | d
 | d   d	 k  rFt  j | |  t  j | |  n  t j | d  | d
 <t j | d
  r°t j | d | d  | d	 <t j | d | d  | d <n) t j | d | d  | d	 <d | d <| | | | | f S(   sņ  Return sequence of transformations from transformation matrix.

    matrix : array_like
        Non-degenerative homogeneous transformation matrix

    Return tuple of:
        scale : vector of 3 scaling factors
        shear : list of shear factors for x-y, x-z, y-z axes
        angles : list of Euler angles about static x, y, z axes
        translate : translation vector along x, y, z axes
        perspective : perspective partition of matrix

    Raise ValueError if matrix is of wrong type or degenerative.

    >>> T0 = translation_matrix([1, 2, 3])
    >>> scale, shear, angles, trans, persp = decompose_matrix(T0)
    >>> T1 = translation_matrix(trans)
    >>> numpy.allclose(T0, T1)
    True
    >>> S = scale_matrix(0.123)
    >>> scale, shear, angles, trans, persp = decompose_matrix(S)
    >>> scale[0]
    0.123
    >>> R0 = euler_matrix(1, 2, 3)
    >>> scale, shear, angles, trans, persp = decompose_matrix(R0)
    >>> R1 = euler_matrix(*angles)
    >>> numpy.allclose(R0, R1)
    True

    R   R   i   s   M[3, 3] is zerog        g      š?Ns   matrix is singulari    i   i   (   i   i   (   i   i   (   g        g        g        g      š?(   i   (   g        g        g        g      š?(   i    i   (   i   i   (   i   i   (   i    i   (   i    i    (   i   i   (   i   i   (   R   R	   R   t   TrueR+   R   R>   R   R   R   t   dett   zerost   anyR   t   invR5   RI   t   negativeR!   t   asinR#   R-   (	   R   R   t   PR;   t   sheart   anglesR9   t	   translatet   row(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   decompose_matrixŌ  sT    !(1"0!
c         C  s«  t  j d  } | d k	 rY t  j d  } | d  | d d d  f <t  j | |  } n  | d k	 r£ t  j d  } | d  | d d  d f <t  j | |  } n  | d k	 rå t | d | d | d d  } t  j | |  } n  | d k	 r?t  j d  }	 | d |	 d <| d |	 d	 <| d |	 d
 <t  j | |	  } n  |  d k	 rt  j d  }
 |  d |
 d <|  d |
 d <|  d |
 d <t  j | |
  } n  | | d } | S(   sc  Return transformation matrix from sequence of transformations.

    This is the inverse of the decompose_matrix function.

    Sequence of transformations:
        scale : vector of 3 scaling factors
        shear : list of shear factors for x-y, x-z, y-z axes
        angles : list of Euler angles about static x, y, z axes
        translate : translation vector along x, y, z axes
        perspective : perspective partition of matrix

    >>> scale = numpy.random.random(3) - 0.5
    >>> shear = numpy.random.random(3) - 0.5
    >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi)
    >>> trans = numpy.random.random(3) - 0.5
    >>> persp = numpy.random.random(4) - 0.5
    >>> M0 = compose_matrix(scale, shear, angles, trans, persp)
    >>> result = decompose_matrix(M0)
    >>> M1 = compose_matrix(*result)
    >>> is_same_transform(M0, M1)
    True

    i   i   Ni    i   i   t   sxyz(   i   i   (   i    i   (   i    i   (   i    i    (   i   i   (   i   i   (   i   i   (   R   R   R%   R   t   euler_matrix(   R;   RX   RY   RZ   R9   R   RW   R+   R)   t   Zt   S(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   compose_matrix)  s4    !c         C  sŪ   |  \ } } } t  j |  } t  j |  \ } } } t  j |  \ } }	 }
 | |	 |
 | | } t  j | | t j d | |  d d d g | | | | | d d g | |	 | | | d g d d d d g g  S(   s·  Return orthogonalization matrix for crystallographic cell coordinates.

    Angles are expected in degrees.

    The de-orthogonalization matrix is the inverse.

    >>> O = orthogonalization_matrix([10, 10, 10], [90, 90, 90])
    >>> numpy.allclose(O[:3, :3], numpy.identity(3, float) * 10)
    True
    >>> O = orthogonalization_matrix([9.8, 12.0, 15.5], [87.2, 80.7, 69.7])
    >>> numpy.allclose(numpy.sum(O), 43.063229)
    True

    g      š?g        (   R   t   radiansR"   R#   R	   R!   t   sqrt(   t   lengthsRY   t   at   bt   cR'   t   sinbt   _R(   t   cosbt   cosgt   co(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   orthogonalization_matrix^  s    (c          C  sķ  t  j |  d t  j d t }  t  j | d t  j d t } |  j d } | d k  sz |  j d | k  sz |  j | j k r t d   n  t  j |  d d } t  j | d  } | | d |  | f <|  | j | d  7}  t  j | d d } t  j | d  }	 | |	 d |  | f <| | j | d  7} | rt  j	 |  | f d d }
 t  j
 j |
 j  \ } } } | |  j } | |  } | | d | !} t  j | t  j
 j |   } t  j	 | t  j | d f  f d d } t  j | d | d f  } nD| s| d k rļt  j
 j t  j | |  j   \ } } } t  j | |  } t  j
 j |  d	 k  r½| t  j | d d  | d f | | d d d  f d  8} | d c d 9<n  t  j | d  } | | d |  d |  f <nWt  j |  | d d \ } } } t  j |  t  j | d d d d d \ } } } t  j |  t  j | d d d d d \ } } } | | | d	 d	 d	 g | | | | | d	 d	 g | | | | | | | d	 g | | | | | | | | | g g } t  j
 j |  \ } } | d d  t  j |  f } | t |  } t |  } | r«| r«|  |  9}  | | 9} | d |  d |  f c t j t  j |  t  j |    9<n  t  j t  j
 j |	  t  j | |   } | | | | f } | S(   s¬  Return affine transform matrix to register two point sets.

    v0 and v1 are shape (ndims, \*) arrays of at least ndims non-homogeneous
    coordinates, where ndims is the dimensionality of the coordinate space.

    If shear is False, a similarity transformation matrix is returned.
    If also scale is False, a rigid/Euclidean transformation matrix
    is returned.

    By default the algorithm by Hartley and Zissermann [15] is used.
    If usesvd is True, similarity and Euclidean transformation matrices
    are calculated by minimizing the weighted sum of squared deviations
    (RMSD) according to the algorithm by Kabsch [8].
    Otherwise, and if ndims is 3, the quaternion based algorithm by Horn [9]
    is used, which is slower when using this Python implementation.

    The returned matrix performs rotation, translation and uniform scaling
    (if specified).

    >>> v0 = [[0, 1031, 1031, 0], [0, 0, 1600, 1600]]
    >>> v1 = [[675, 826, 826, 677], [55, 52, 281, 277]]
    >>> affine_matrix_from_points(v0, v1)
    array([[   0.14549,    0.00062,  675.50008],
           [   0.00048,    0.14094,   53.24971],
           [   0.     ,    0.     ,    1.     ]])
    >>> T = translation_matrix(numpy.random.random(3)-0.5)
    >>> R = random_rotation_matrix(numpy.random.random(3))
    >>> S = scale_matrix(random.random())
    >>> M = concatenate_matrices(T, R, S)
    >>> v0 = (numpy.random.rand(4, 100) - 0.5) * 20
    >>> v0[3] = 1
    >>> v1 = numpy.dot(M, v0)
    >>> v0[:3] += numpy.random.normal(0, 1e-8, 300).reshape(3, -1)
    >>> M = affine_matrix_from_points(v0[:3], v1[:3])
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True

    More examples in superimposition_matrix()

    R   R   i    i   i   s'   input arrays are of wrong shape or typet   axisNg        g      š?i   g       @i’’’’g      šæiž’’’(   g        (   g      š?(   R   R	   R   RP   t   shapeR   t   meanR   t   reshapet   concatenateR   t   svdR+   R   t   pinvRR   t   vstackRQ   R   t   sumt   rollt   eight   argmaxR5   t   quaternion_matrixR!   Rc   RT   (    t   v0t   v1RX   R;   t   usesvdt   ndimst   t0t   M0t   t1t   M1t   At   ut   st   vht   Bt   CRE   R   R)   t   xxt   yyt   zzt   xyt   yzt   zxt   xzt   yxt   zyt   NR   R   t   q(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   affine_matrix_from_pointsy  s`    )1
* *B"44)

D*c      	   C  sc   t  j |  d t  j d t d  }  t  j | d t  j d t d  } t |  | d t d | d | S(   sd  Return matrix to transform given 3D point set into second point set.

    v0 and v1 are shape (3, \*) or (4, \*) arrays of at least 3 points.

    The parameters scale and usesvd are explained in the more general
    affine_matrix_from_points function.

    The returned matrix is a similarity or Euclidean transformation matrix.
    This function has a fast C implementation in transformations.c.

    >>> v0 = numpy.random.rand(3, 10)
    >>> M = superimposition_matrix(v0, v0)
    >>> numpy.allclose(M, numpy.identity(4))
    True
    >>> R = random_rotation_matrix(numpy.random.random(3))
    >>> v0 = [[1,0,0], [0,1,0], [0,0,1], [1,1,1]]
    >>> v1 = numpy.dot(R, v0)
    >>> M = superimposition_matrix(v0, v1)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> v0 = (numpy.random.rand(4, 100) - 0.5) * 20
    >>> v0[3] = 1
    >>> v1 = numpy.dot(R, v0)
    >>> M = superimposition_matrix(v0, v1)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> S = scale_matrix(random.random())
    >>> T = translation_matrix(numpy.random.random(3)-0.5)
    >>> M = concatenate_matrices(T, R, S)
    >>> v1 = numpy.dot(M, v0)
    >>> v0[:3] += numpy.random.normal(0, 1e-9, 300).reshape(3, -1)
    >>> M = superimposition_matrix(v0, v1, scale=True)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> M = superimposition_matrix(v0, v1, scale=True, usesvd=False)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> v = numpy.empty((4, 100, 3))
    >>> v[:, :, 0] = v0
    >>> M = superimposition_matrix(v0, v1, scale=True, usesvd=False)
    >>> numpy.allclose(v1, numpy.dot(M, v[:, :, 0]))
    True

    R   R   i   RX   R;   R}   (   R   R	   R   R
   R   (   R{   R|   R;   R}   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   superimposition_matrixę  s    -""R]   c         C  sŅ  y t  | \ } } } } Wn1 t t f k
 rM t | | \ } } } } n X| } t | | }	 t | | d }
 | r | |  }  } n  | rŖ |  | | }  } } n  t j |   t j |  t j |  } } } t j |   t j |  t j |  } } } | | | | } } | | | | } } t j	 d  } | r| | | | f <| | | | |	 f <| | | | |
 f <| | | |	 | f <| | | | |	 |	 f <| | | | |	 |
 f <| | | |
 | f <| | | | |
 |	 f <| | | | |
 |
 f <nĮ | | | | | f <| | | | | |	 f <| | | | | |
 f <| | | |	 | f <| | | | |	 |	 f <| | | | |	 |
 f <| | |
 | f <| | | |
 |	 f <| | | |
 |
 f <| S(   s  Return homogeneous rotation matrix from Euler angles and axis sequence.

    ai, aj, ak : Euler's roll, pitch and yaw angles
    axes : One of 24 axis sequences as string or encoded tuple

    >>> R = euler_matrix(1, 2, 3, 'syxz')
    >>> numpy.allclose(numpy.sum(R[0]), -1.34786452)
    True
    >>> R = euler_matrix(1, 2, 3, (0, 1, 0, 1))
    >>> numpy.allclose(numpy.sum(R[0]), -0.383436184)
    True
    >>> ai, aj, ak = (4*math.pi) * (numpy.random.random(3) - 0.5)
    >>> for axes in _AXES2TUPLE.keys():
    ...    R = euler_matrix(ai, aj, ak, axes)
    >>> for axes in _TUPLE2AXES.keys():
    ...    R = euler_matrix(ai, aj, ak, axes)

    i   i   (
   t   _AXES2TUPLEt   AttributeErrort   KeyErrort   _TUPLE2AXESt
   _NEXT_AXISR!   R"   R#   R   R   (   t   ait   ajt   akt   axest	   firstaxist   parityt
   repetitiont   frameR   t   jt   kt   sit   sjt   skt   cit   cjt   ckt   cct   cst   sct   ssR   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR^     sJ    //c         C  s  y  t  | j   \ } } } } Wn1 t t f k
 rS t | | \ } } } } n X| } t | | } t | | d } t j |  d t j d t	 d d  d d  f }	 | r»t
 j |	 | | f |	 | | f |	 | | f |	 | | f  }
 |
 t k rot
 j |	 | | f |	 | | f  } t
 j |
 |	 | | f  } t
 j |	 | | f |	 | | f  } qĄt
 j |	 | | f |	 | | f  } t
 j |
 |	 | | f  } d } nt
 j |	 | | f |	 | | f |	 | | f |	 | | f  } | t k rvt
 j |	 | | f |	 | | f  } t
 j |	 | | f |  } t
 j |	 | | f |	 | | f  } nJ t
 j |	 | | f |	 | | f  } t
 j |	 | | f |  } d } | rą| | | } } } n  | rö| | } } n  | | | f S(   s  Return Euler angles from rotation matrix for specified axis sequence.

    axes : One of 24 axis sequences as string or encoded tuple

    Note that many Euler angle triplets can describe one matrix.

    >>> R0 = euler_matrix(1, 2, 3, 'syxz')
    >>> al, be, ga = euler_from_matrix(R0, 'syxz')
    >>> R1 = euler_matrix(al, be, ga, 'syxz')
    >>> numpy.allclose(R0, R1)
    True
    >>> angles = (4*math.pi) * (numpy.random.random(3) - 0.5)
    >>> for axes in _AXES2TUPLE.keys():
    ...    R0 = euler_matrix(axes=axes, *angles)
    ...    R1 = euler_matrix(axes=axes, *euler_from_matrix(R0, axes))
    ...    if not numpy.allclose(R0, R1): print(axes, "failed")

    i   R   R   Ni   g        (   R   t   lowerR   R   R   R   R   R	   R   R
   R!   Rc   R>   R-   (   R   R   R   R    R”   R¢   R   R£   R¤   R   t   syt   axt   ayt   azt   cy(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   euler_from_matrixX  s>     4C&*'	C&)'c         C  s   t  t |   |  S(   sÅ   Return Euler angles from quaternion for specified axis sequence.

    >>> angles = euler_from_quaternion([0.99810947, 0.06146124, 0, 0])
    >>> numpy.allclose(angles, [0.123, 0, 0])
    True

    (   Rµ   Rz   (   t
   quaternionR   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   euler_from_quaternion  s    c         C  s!  y  t  | j   \ } } } } Wn1 t t f k
 rS t | | \ } } } } n X| d } t | | d d }	 t | | d }
 | r | |  }  } n  | r¬ | } n  |  d }  | d } | d } t j |   } t j |   } t j |  } t j |  } t j |  } t j |  } | | } | | } | | } | | } t	 j
 d  } | r¬| | | | d <| | | | | <| | | | |	 <| | | | |
 <nX | | | | | d <| | | | | | <| | | | | |	 <| | | | | |
 <| r| |	 c d 9<n  | S(   s2  Return quaternion from Euler angles and axis sequence.

    ai, aj, ak : Euler's roll, pitch and yaw angles
    axes : One of 24 axis sequences as string or encoded tuple

    >>> q = quaternion_from_euler(1, 2, 3, 'ryxz')
    >>> numpy.allclose(q, [0.435953, 0.310622, -0.718287, 0.444435])
    True

    i   g       @i   i    g      šæ(   i   (   R   RÆ   R   R   R   R   R!   R#   R"   R   t   empty(   R   R   R   R   R   R    R”   R¢   R   R£   R¤   RØ   R„   R©   R¦   RŖ   R§   R«   R¬   R­   R®   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_from_euler  sL     








c         C  sx   t  j d | d | d | d g  } t |  } | t k r] | t j |  d  | 9} n  t j |  d  | d <| S(   sØ   Return quaternion for rotation about axis.

    >>> q = quaternion_about_axis(0.123, [1, 0, 0])
    >>> numpy.allclose(q, [0.99810947, 0.06146124, 0, 0])
    True

    g        i    i   i   g       @(   R   R	   R5   R>   R!   R"   R#   (   R&   Rn   R   t   qlen(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_about_axisÖ  s    'c      	   C  s3  t  j |  d t  j d t } t  j | |  } | t k  rI t  j d  S| t j d |  9} t  j	 | |  } t  j d | d | d | d | d | d | d d
 g | d | d d | d | d | d | d d
 g | d | d | d | d d | d | d d
 g d
 d
 d
 d g g  S(   s  Return homogeneous rotation matrix from quaternion.

    >>> M = quaternion_matrix([0.99810947, 0.06146124, 0, 0])
    >>> numpy.allclose(M, rotation_matrix(0.123, [1, 0, 0]))
    True
    >>> M = quaternion_matrix([1, 0, 0, 0])
    >>> numpy.allclose(M, numpy.identity(4))
    True
    >>> M = quaternion_matrix([0, 1, 0, 0])
    >>> numpy.allclose(M, numpy.diag([1, -1, -1, 1]))
    True

    R   R   i   g       @g      š?i   i   i   i    g        (   i   i   (   i   i   (   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   i   i   (   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   i   i   (
   R   R	   R   RP   R   R>   R   R!   Rc   R   (   R¶   R   RN   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyRz   ę  s    777c      	   C  s?  t  j |  d t  j d t d d  d d  f } | rōt  j d  } t  j |  } | | d k r· | | d <| d | d | d <| d | d | d <| d | d | d <nd \ } } } | d | d k rģ d \ } } } n  | d | | | f k rd \ } } } n  | | | f | | | f | | | f | d } | | | <| | | f | | | f | | <| | | f | | | f | | <| | | f | | | f | d <| d d d d g } | d	 t j | | d  9} n$| d } | d }	 | d }
 | d } | d  } | d! } | d" } | d# } | d$ } t  j | | | d
 d
 d
 g |	 | | | | d
 d
 g |
 | | | | | | d
 g | | |
 | | |	 | | | g g  } | d } t  j j	 |  \ } } | d d d d g t  j
 |  f } | d d
 k  r;t  j | |  n  | S(%   s  Return quaternion from rotation matrix.

    If isprecise is True, the input matrix is assumed to be a precise rotation
    matrix and a faster algorithm is used.

    >>> q = quaternion_from_matrix(numpy.identity(4), True)
    >>> numpy.allclose(q, [1, 0, 0, 0])
    True
    >>> q = quaternion_from_matrix(numpy.diag([1, -1, -1, 1]))
    >>> numpy.allclose(q, [0, 1, 0, 0]) or numpy.allclose(q, [0, -1, 0, 0])
    True
    >>> R = rotation_matrix(0.123, (1, 2, 3))
    >>> q = quaternion_from_matrix(R, True)
    >>> numpy.allclose(q, [0.9981095, 0.0164262, 0.0328524, 0.0492786])
    True
    >>> R = [[-0.545, 0.797, 0.260, 0], [0.733, 0.603, -0.313, 0],
    ...      [-0.407, 0.021, -0.913, 0], [0, 0, 0, 1]]
    >>> q = quaternion_from_matrix(R)
    >>> numpy.allclose(q, [0.19069, 0.43736, 0.87485, -0.083611])
    True
    >>> R = [[0.395, 0.362, 0.843, 0], [-0.626, 0.796, -0.056, 0],
    ...      [-0.677, -0.498, 0.529, 0], [0, 0, 0, 1]]
    >>> q = quaternion_from_matrix(R)
    >>> numpy.allclose(q, [0.82336615, -0.13610694, 0.46344705, -0.29792603])
    True
    >>> R = random_rotation_matrix()
    >>> q = quaternion_from_matrix(R)
    >>> is_same_transform(R, quaternion_matrix(q))
    True
    >>> is_same_quaternion(quaternion_from_matrix(R, isprecise=False),
    ...                    quaternion_from_matrix(R, isprecise=True))
    True
    >>> R = euler_matrix(0.0, 0.0, numpy.pi/2.0)
    >>> is_same_quaternion(quaternion_from_matrix(R, isprecise=False),
    ...                    quaternion_from_matrix(R, isprecise=True))
    True

    R   R   Ni   i   i    i   i   g      ą?g        g      @(   i   (   i   i   (   i   i    (   i    i   (   i    i   (   i   i    (   i   i   (   i   i   (   i    i   i   (   i   i   (   i    i    (   i   i   i    (   i   i   (   i   i    i   (   i   i   (   i   i   (   i    i    (   i    i   (   i    i   (   i   i    (   i   i   (   i   i   (   i   i    (   i   i   (   i   i   (   R   R	   R   R
   Rø   R,   R!   Rc   R   Rx   Ry   RU   (   R   t	   ispreciseR   R   RE   R   R£   R¤   t   m00t   m01t   m02t   m10t   m11t   m12t   m20t   m21t   m22t   KR   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_from_matrix  sP    '4
4
""""








,
%c   
      C  sø   | \ } } } } |  \ } } } }	 t  j | | | | |	 | | | | | | | |	 | | | | | | | |	 | | | | | | | |	 | | | g d t  j S(   s„   Return multiplication of two quaternions.

    >>> q = quaternion_multiply([4, 1, -2, 3], [8, -5, 6, 7])
    >>> numpy.allclose(q, [28, -44, -14, 48])
    True

    R   (   R   R	   R   (
   t   quaternion1t   quaternion0t   w0t   x0t   y0t   z0t   w1t   x1t   y1t   z1(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_multiplyV  s      c         C  s:   t  j |  d t  j d t } t  j | d | d  | S(   sØ   Return conjugate of quaternion.

    >>> q0 = random_quaternion()
    >>> q1 = quaternion_conjugate(q0)
    >>> q1[0] == q0[0] and all(q1[1:] == -q0[1:])
    True

    R   R   i   (   R   R	   R   RP   RU   (   R¶   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_conjugateg  s    	c         C  sJ   t  j |  d t  j d t } t  j | d | d  | t  j | |  S(   s“   Return inverse of quaternion.

    >>> q0 = random_quaternion()
    >>> q1 = quaternion_inverse(q0)
    >>> numpy.allclose(quaternion_multiply(q0, q1), [1, 0, 0, 0])
    True

    R   R   i   (   R   R	   R   RP   RU   R   (   R¶   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_inverseu  s    	c         C  s   t  |  d  S(   sT   Return real part of quaternion.

    >>> quaternion_real([3, 0, 1, 2])
    3.0

    i    (   t   float(   R¶   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_real  s    c         C  s#   t  j |  d d !d t  j d t S(   sl   Return imaginary part of quaternion.

    >>> quaternion_imag([3, 0, 1, 2])
    array([ 0.,  1.,  2.])

    i   i   R   R   (   R   R	   R   RP   (   R¶   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_imag  s    i    c   
      C  s)  t  |  d   } t  | d   } | d k r0 | S| d k r@ | St j | |  } t t |  d  t k  rr | S| r | d k  r | } t j | |  n  t j |  | t j } t |  t k  rĪ | Sd t j	 |  }	 | t j	 d | |  |	 9} | t j	 | |  |	 9} | | 7} | S(   s  Return spherical linear interpolation between two quaternions.

    >>> q0 = random_quaternion()
    >>> q1 = random_quaternion()
    >>> q = quaternion_slerp(q0, q1, 0)
    >>> numpy.allclose(q, q0)
    True
    >>> q = quaternion_slerp(q0, q1, 1, 1)
    >>> numpy.allclose(q, q1)
    True
    >>> q = quaternion_slerp(q0, q1, 0.5)
    >>> angle = math.acos(numpy.dot(q0, q))
    >>> numpy.allclose(2, math.acos(numpy.dot(q0, q1)) / angle) or         numpy.allclose(2, math.acos(-numpy.dot(q0, q1)) / angle)
    True

    i   g        g      š?(
   R   R   R   R   R>   RU   R!   t   acost   piR"   (
   t   quat0t   quat1t   fractiont   spint   shortestpatht   q0t   q1t   dR&   t   isin(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   quaternion_slerp  s(    
c         C  sŁ   |  d k r! t j j d  }  n t |   d k s9 t  t j d |  d  } t j |  d  } t j d } | |  d } | |  d } t j	 t j
 |  | t j |  | t j
 |  | t j |  | g  S(   si  Return uniform random unit quaternion.

    rand: array like or None
        Three independent random variables that are uniformly distributed
        between 0 and 1.

    >>> q = random_quaternion()
    >>> numpy.allclose(1, vector_norm(q))
    True
    >>> q = random_quaternion(numpy.random.random(3))
    >>> len(q.shape), q.shape[0]==4
    (1, True)

    i   g      š?i    g       @i   i   N(   R%   R   t   randomt   randR   t   AssertionErrorRc   R!   RŁ   R	   R#   R"   (   Rå   t   r1t   r2t   pi2R   t   t2(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   random_quaternionĄ  s    &c         C  s   t  t |    S(   s.  Return uniform random rotation matrix.

    rand: array like
        Three independent random variables that are uniformly distributed
        between 0 and 1 for each returned quaternion.

    >>> R = random_rotation_matrix()
    >>> numpy.allclose(numpy.dot(R.T, R), numpy.identity(4))
    True

    (   Rz   Rė   (   Rå   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   random_rotation_matrixÜ  s    t   Arcballc           B  st   e  Z d  Z d d  Z d   Z d   Z e d    Z e j	 d    Z d   Z
 d   Z d d	  Z d
   Z RS(   s^  Virtual Trackball Control.

    >>> ball = Arcball()
    >>> ball = Arcball(initial=numpy.identity(4))
    >>> ball.place([320, 320], 320)
    >>> ball.down([500, 250])
    >>> ball.drag([475, 275])
    >>> R = ball.matrix()
    >>> numpy.allclose(numpy.sum(R), 3.90583455)
    True
    >>> ball = Arcball(initial=[1, 0, 0, 0])
    >>> ball.place([320, 320], 320)
    >>> ball.setaxes([1, 1, 0], [-1, 1, 0])
    >>> ball.constrain = True
    >>> ball.down([400, 200])
    >>> ball.drag([200, 400])
    >>> R = ball.matrix()
    >>> numpy.allclose(numpy.sum(R), 0.2055924)
    True
    >>> ball.next()

    c         C  s  d |  _ d |  _ d |  _ d d g |  _ t j d d d g  |  _ t |  _	 | d k r{ t j d d d d g  |  _
 np t j | d t j } | j d k r“ t |  |  _
 n7 | j d k rß | t |  } | |  _
 n t d   |  j
 |  _ |  _ d S(	   s`   Initialize virtual trackball control.

        initial : quaternion or rotation matrix

        g      š?g        R   i   s"   initial not a quaternion or matrixN(   i   i   (   i   (   R%   t   _axist   _axest   _radiust   _centerR   R	   t   _vdownR
   t
   _constraint   _qdownR   Ro   RĒ   R5   R   t   _qnowt   _qpre(   t   selft   initial(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   __init__  s     				!c         C  s5   t  |  |  _ | d |  j d <| d |  j d <d S(   s×   Place Arcball, e.g. when window size changes.

        center : sequence[2]
            Window coordinates of trackball center.
        radius : float
            Radius of trackball in window coordinates.

        i    i   N(   RÕ   Rš   Rń   (   R÷   t   centert   radius(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   place  s    	c         G  s>   | d k r d |  _ n" g  | D] } t |  ^ q |  _ d S(   s    Set axes to constrain rotations.N(   R%   Rļ   R   (   R÷   R   Rn   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   setaxes)  s    c         C  s   |  j  S(   s'   Return state of constrain to axis mode.(   Ró   (   R÷   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt	   constrain0  s    c         C  s   t  |  |  _ d S(   s$   Set state of constrain to axis mode.N(   t   boolRó   (   R÷   t   value(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyRž   5  s    c         C  s   t  | |  j |  j  |  _ |  j |  _ |  _ |  j ry |  j d k	 ry t
 |  j |  j  |  _ t |  j |  j  |  _ n	 d |  _ d S(   s>   Set initial cursor window coordinates and pick constrain-axis.N(   t   arcball_map_to_sphereRń   Rš   Rņ   Rõ   Rō   Rö   Ró   Rļ   R%   t   arcball_nearest_axisRī   t   arcball_constrain_to_axis(   R÷   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   down:  s    c         C  sŹ   t  | |  j |  j  } |  j d k	 r< t | |  j  } n  |  j |  _ t j	 |  j
 |  } t j | |  t k  r |  j |  _ nB t j |  j
 |  | d | d | d g } t | |  j  |  _ d S(   s)   Update current cursor window coordinates.i    i   i   N(   R  Rń   Rš   Rī   R%   R  Rõ   Rö   R   RI   Rņ   R   R>   Rō   RŅ   (   R÷   R   t   vnowRE   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   dragD  s    -g        c         C  s9   t  |  j |  j d | t  } |  j | |  _ |  _ d S(   s,   Continue rotation in direction of last drag.g       @N(   Rć   Rö   Rõ   R
   (   R÷   t   accelerationR   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   nextQ  s    c         C  s   t  |  j  S(   s#   Return homogeneous rotation matrix.(   Rz   Rõ   (   R÷   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR   V  s    N(   t   __name__t
   __module__t   __doc__R%   Rł   Rü   Rż   t   propertyRž   t   setterR  R  R  R   (    (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyRķ   ė  s   			
	c         C  s   |  d | d | } | d |  d | } | | | | } | d k rw t  j |  } t j | | | | d g  St j | | t  j d |  g  Sd S(   s7   Return unit sphere coordinates from window coordinates.i    i   g      š?g        N(   R!   Rc   R   R	   (   R   Rś   Rū   R{   R|   RN   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR  [  s    c         C  sį   t  j |  d t  j d t } t  j | d t  j d t } | | t  j | |  8} t |  } | t k r | d d k  r t  j | |  n  | | } | S| d d k rÅ t  j d d d g  St | d | d d g  S(   s*   Return sphere point perpendicular to axis.R   R   i   g        g      š?i   i    (	   R   R	   R   RP   R   R5   R>   RU   R   (   R   Rn   t   vRe   RN   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR  h  s    
c         C  su   t  j |  d t  j d t }  d } d } xD | D]< } t  j t |  |  |   } | | k r1 | } | } q1 q1 W| S(   s+   Return axis, which arc is nearest to point.R   R   g      šæN(   R   R	   R   R
   R%   R   R  (   R   R   t   nearestt   mxRn   RE   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR  x  s    g      @i   i   t   sxyxt   sxzyt   sxzxt   syzxt   syzyt   syxzt   syxyt   szxyt   szxzt   szyxt   szyzt   rzyxt   rxyxt   ryzxt   rxzxt   rxzyt   ryzyt   rzxyt   ryxyt   ryxzt   rzxzt   rxyzt   rzyzc         c  s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0R¤   R  (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pys	   <genexpr>  s    c         C  sÅ   t  j |  d t  j d t }  | d k r |  j d k rR t j t  j |  |    S|  |  9}  t  j	 t  j
 |  d |  } t  j | |  | S|  |  9}  t  j
 |  d | d | t  j | |  d S(   s©  Return length, i.e. Euclidean norm, of ndarray along axis.

    >>> v = numpy.random.random(3)
    >>> n = vector_norm(v)
    >>> numpy.allclose(n, numpy.linalg.norm(v))
    True
    >>> v = numpy.random.rand(6, 5, 3)
    >>> n = vector_norm(v, axis=-1)
    >>> numpy.allclose(n, numpy.sqrt(numpy.sum(v*v, axis=2)))
    True
    >>> n = vector_norm(v, axis=1)
    >>> numpy.allclose(n, numpy.sqrt(numpy.sum(v*v, axis=1)))
    True
    >>> v = numpy.random.rand(5, 4, 3)
    >>> n = numpy.empty((5, 3))
    >>> vector_norm(v, axis=1, out=n)
    >>> numpy.allclose(n, numpy.sqrt(numpy.sum(v*v, axis=1)))
    True
    >>> vector_norm([])
    0.0
    >>> vector_norm([1])
    1.0

    R   R   i   Rn   t   outN(   R   R	   R   RP   R%   t   ndimR!   Rc   R   t
   atleast_1dRv   (   t   dataRn   R)  (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR5     s    

c         C  sų   | d k r_ t j |  d t j d t }  |  j d k r |  t j t j |  |    }  |  Sn+ | |  k	 r t j |  d t	 | (n  | }  t j
 t j |  |  |   } t j | |  | d k	 rŚ t j | |  } n  |  | }  | d k rō |  Sd S(   sģ  Return ndarray normalized by length, i.e. Euclidean norm, along axis.

    >>> v0 = numpy.random.random(3)
    >>> v1 = unit_vector(v0)
    >>> numpy.allclose(v1, v0 / numpy.linalg.norm(v0))
    True
    >>> v0 = numpy.random.rand(5, 4, 3)
    >>> v1 = unit_vector(v0, axis=-1)
    >>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=2)), 2)
    >>> numpy.allclose(v1, v2)
    True
    >>> v1 = unit_vector(v0, axis=1)
    >>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=1)), 1)
    >>> numpy.allclose(v1, v2)
    True
    >>> v1 = numpy.empty((5, 4, 3))
    >>> unit_vector(v0, axis=1, out=v1)
    >>> numpy.allclose(v1, v2)
    True
    >>> list(unit_vector([]))
    []
    >>> list(unit_vector([1]))
    [1.0]

    R   R   i   N(   R%   R   R	   R   RP   R*  R!   Rc   R   R
   R+  Rv   t   expand_dims(   R,  Rn   R)  t   length(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyR   Ą  s    
c         C  s   t  j j |   S(   s  Return array of random doubles in the half-open interval [0.0, 1.0).

    >>> v = random_vector(10000)
    >>> numpy.all(v >= 0) and numpy.all(v < 1)
    True
    >>> v0 = random_vector(10)
    >>> v1 = random_vector(10)
    >>> numpy.any(v0 == v1)
    False

    (   R   Rä   (   t   size(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   random_vectorģ  s    c         C  s   t  j |  | d | S(   sH  Return vector perpendicular to vectors.

    >>> v = vector_product([2, 0, 0], [0, 3, 0])
    >>> numpy.allclose(v, [0, 0, 6])
    True
    >>> v0 = [[2, 0, 0, 2], [0, 2, 0, 2], [0, 0, 2, 2]]
    >>> v1 = [[3], [0], [0]]
    >>> v = vector_product(v0, v1)
    >>> numpy.allclose(v, [[0, 0, 0, 0], [0, 0, 6, 6], [0, -6, 0, -6]])
    True
    >>> v0 = [[2, 0, 0], [2, 0, 0], [0, 2, 0], [2, 0, 0]]
    >>> v1 = [[0, 3, 0], [0, 0, 3], [0, 0, 3], [3, 3, 3]]
    >>> v = vector_product(v0, v1, axis=1)
    >>> numpy.allclose(v, [[0, 0, 6], [0, -6, 0], [6, 0, 0], [0, -6, 6]])
    True

    Rn   (   R   RI   (   R{   R|   Rn   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   vector_productū  s    c         C  s²   t  j |  d t  j d t }  t  j | d t  j d t } t  j |  | d | } | t |  d | t | d | } t  j | d d  } t  j | r¢ | n t  j |   S(   s  Return angle between vectors.

    If directed is False, the input vectors are interpreted as undirected axes,
    i.e. the maximum angle is pi/2.

    >>> a = angle_between_vectors([1, -2, 3], [-1, 2, -3])
    >>> numpy.allclose(a, math.pi)
    True
    >>> a = angle_between_vectors([1, -2, 3], [-1, 2, -3], directed=False)
    >>> numpy.allclose(a, 0)
    True
    >>> v0 = [[2, 0, 0, 2], [0, 2, 0, 2], [0, 0, 2, 2]]
    >>> v1 = [[3], [0], [0]]
    >>> a = angle_between_vectors(v0, v1)
    >>> numpy.allclose(a, [0, 1.5708, 1.5708, 0.95532])
    True
    >>> v0 = [[2, 0, 0], [2, 0, 0], [0, 2, 0], [2, 0, 0]]
    >>> v1 = [[0, 3, 0], [0, 0, 3], [0, 0, 3], [3, 3, 3]]
    >>> a = angle_between_vectors(v0, v1, axis=1)
    >>> numpy.allclose(a, [1.5708, 1.5708, 1.5708, 0.95532])
    True

    R   R   Rn   g      šæg      š?(	   R   R	   R   R
   Rv   R5   t   clipt   arccost   fabs(   R{   R|   t   directedRn   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   angle_between_vectors  s    &c         C  s   t  j j |   S(   sw  Return inverse of square transformation matrix.

    >>> M0 = random_rotation_matrix()
    >>> M1 = inverse_matrix(M0.T)
    >>> numpy.allclose(M1, numpy.linalg.inv(M0.T))
    True
    >>> for size in range(1, 7):
    ...     M0 = numpy.random.rand(size, size)
    ...     M1 = inverse_matrix(M0)
    ...     if not numpy.allclose(M1, numpy.linalg.inv(M0)): print(size)

    (   R   R   RT   (   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   inverse_matrix0  s    c          G  s6   t  j d  } x  |  D] } t  j | |  } q W| S(   s  Return concatenation of series of transformation matrices.

    >>> M = numpy.random.rand(16).reshape((4, 4)) - 0.5
    >>> numpy.allclose(M, concatenate_matrices(M))
    True
    >>> numpy.allclose(numpy.dot(M, M.T), concatenate_matrices(M, M.T))
    True

    i   (   R   R   R   (   t   matricesR   R   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   concatenate_matrices@  s    
c         C  sh   t  j |  d t  j d t }  |  |  d }  t  j | d t  j d t } | | d } t  j |  |  S(   sŁ   Return True if two matrices perform same transformation.

    >>> is_same_transform(numpy.identity(4), numpy.identity(4))
    True
    >>> is_same_transform(numpy.identity(4), random_rotation_matrix())
    False

    R   R   i   (   i   i   (   i   i   (   R   R	   R   RP   t   allclose(   t   matrix0t   matrix1(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   is_same_transformP  s
    	c         C  sA   t  j |   }  t  j |  } t  j |  |  p@ t  j |  |  S(   s)   Return True if two quaternions are equal.(   R   R	   R:  (   Rß   Rą   (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   is_same_quaternion`  s    t   _py_Ri   c   	      C  s  d d l  } d d l m } y/ | s4 | |   } n | d |  d | } Wn+ t k
 rx | r| j d |   qn Xx t |  D] } | r§ | j |  r§ q n  | rō | t   k r× t   | t   | | <qō | rō | j d |  qō n  t | |  t   | <q Wt	 Sd S(   sō   Try import all public attributes from module into global namespace.

    Existing attributes with name clashes are renamed with prefix.
    Attributes starting with underscore are ignored by default.

    Return True on successful import.

    i’’’’N(   t   import_modulet   .t   packages   failed to import module %ss   no Python implementation of (
   t   warningst	   importlibR@  t   ImportErrort   warnt   dirt
   startswitht   globalst   getattrRP   (	   t   nameRB  RF  t   prefixt   ignoreRC  R@  t   modulet   attr(    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   _import_moduleg  s&    	t   _transformationst   __main__t   suppresst	   precisioni   t   legacys   1.13(    (   i    i    i    i    (   i    i    i   i    (   i    i   i    i    (   i    i   i   i    (   i   i    i    i    (   i   i    i   i    (   i   i   i    i    (   i   i   i   i    (   i   i    i    i    (   i   i    i   i    (   i   i   i    i    (   i   i   i   i    (   i    i    i    i   (   i    i    i   i   (   i    i   i    i   (   i    i   i   i   (   i   i    i    i   (   i   i    i   i   (   i   i   i    i   (   i   i   i   i   (   i   i    i    i   (   i   i    i   i   (   i   i   i    i   (   i   i   i   i   (L   R  t
   __future__R    R   R!   R   t   __version__t   __docformat__t   __all__R   R   R   R   R    R%   R*   R1   R4   R8   R
   R<   R=   RF   RH   RO   R\   Ra   Rm   RP   R   R   R^   Rµ   R·   R¹   R»   Rz   RĒ   RŅ   RÓ   RŌ   RÖ   R×   Rć   Rė   Rģ   t   objectRķ   R  R  R  t   finfoRÕ   t   epsR>   R   R   t   dictt   itemsR   R5   R   R0  R1  R6  R7  R9  R=  R>  RP  R	  t   doctestRä   t   set_printoptionst	   TypeErrort   testmod(    (    (    s^   /home/filipe/Documents/Dissertacao/Optimization/OpenConstructorOptimization/transformations.pyt   <module>Ā   s   					,	("	)=I4		-	U4	m3?:9		U				
	
)p			',	 				 
 