# Path: imusim/maths/transforms.py
# class AffineTransform(object):
# class UnscentedTransform(object):
#     def __init__(self, transform=None, rz=0, ry=0, rx=0, scale=1,
#             translation=vector(0,0,0)):
#     def apply(self,v):
#     def reverse(self,v):
#     def __init__(self, function):
#     def __call__(self, mean, covariance, *args, **kwargs):
#     def sigmaPoints(mean, covariance):
# def cartesianToPolar(x,y):
# def polarToCartesian(r,theta):
# def convertCGtoNED(param):
# def convertNEDtoCG(param):
#         N = len(mean)
# 
# Path: imusim/maths/transforms.py
# class AffineTransform(object):
#     """
#     Affine transform composed of a linear transform matrix and translation.
#     """
#     def __init__(self, transform=None, rz=0, ry=0, rx=0, scale=1,
#             translation=vector(0,0,0)):
#         """
#         Construct an affine transform.
# 
#         A generic transformation matrix can be supplied, or a transform
#         composed of rotation and scaling can be built.
# 
#         Generating rotations using supplied Euler angles is performed from the
#         perspective of a fixed camera viewing a rotating object, i.e. points
#         rotate within a fixed reference frame. Rotations are applied in
#         aerospace (ZYX) order.
# 
#         @param transform: 3x3 linear transformation matrix.
#         @param rx: X rotation angle in radians.
#         @param ry: Y rotation angle in radians.
#         @param rz: Z rotation angle in radians.
#         @param scale: Scaling factor
#         @param translation: 3x1 translation vector.
#         """
#         if transform is not None:
#             self._transform = transform
#         else:
#             self._transform = scale * matrixFromEuler((rz,ry,rx),'zyx',False)
# 
#         self._inverseTransform = np.linalg.inv(self._transform)
#         self._translation = translation
# 
#     def apply(self,v):
#         """
#         Apply transform to an array of column vectors.
#         """
#         return np.tensordot(self._transform, v, axes=([1],[0])) \
#                 + self._translation
# 
#     def reverse(self,v):
#         """
#         Apply the inverse of this transform to an array of column vectors.
#         """
#         return np.tensordot(self._inverseTransform,
#                 v-self._translation,axes=([1],[0]))


import numpy as np
from numpy import random
from scipy import stats
from numpy import testing
from imusim.maths import transforms
from imusim.maths.vectors import vector
from imusim.maths.quaternions import Quaternion
from imusim.maths.transforms import AffineTransform
from math import sqrt
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IMUSim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IMUSim.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import division

RANDOM_SEED=0

def assert_almost_equal(a, b):
    for ai, bi in zip(a, b):
        testing.assert_almost_equal(ai, bi)

# each element of the list is a tuple of cartesian and polar co-ords
CARTESIAN_POLAR_TEST_VALUES = [
        ((0,0),(0,0)),
        ((0,1),(1,np.pi/2)),
        ((1,0),(1,0)),
        ((1/sqrt(2), 1/sqrt(2)), (1,np.pi/4)),
        ((0,10),(10,np.pi/2)),
        ((5,0),(5,0))
        ]
def checkPolarToCartesian(cartesian, polar):

# Path: imusim/maths/transforms.py
# class AffineTransform(object):
# class UnscentedTransform(object):
#     def __init__(self, transform=None, rz=0, ry=0, rx=0, scale=1,
#             translation=vector(0,0,0)):
#     def apply(self,v):
#     def reverse(self,v):
#     def __init__(self, function):
#     def __call__(self, mean, covariance, *args, **kwargs):
#     def sigmaPoints(mean, covariance):
# def cartesianToPolar(x,y):
# def polarToCartesian(r,theta):
# def convertCGtoNED(param):
# def convertNEDtoCG(param):
#         N = len(mean)
# 
# Path: imusim/maths/transforms.py
# class AffineTransform(object):
#     """
#     Affine transform composed of a linear transform matrix and translation.
#     """
#     def __init__(self, transform=None, rz=0, ry=0, rx=0, scale=1,
#             translation=vector(0,0,0)):
#         """
#         Construct an affine transform.
# 
#         A generic transformation matrix can be supplied, or a transform
#         composed of rotation and scaling can be built.
# 
#         Generating rotations using supplied Euler angles is performed from the
#         perspective of a fixed camera viewing a rotating object, i.e. points
#         rotate within a fixed reference frame. Rotations are applied in
#         aerospace (ZYX) order.
# 
#         @param transform: 3x3 linear transformation matrix.
#         @param rx: X rotation angle in radians.
#         @param ry: Y rotation angle in radians.
#         @param rz: Z rotation angle in radians.
#         @param scale: Scaling factor
#         @param translation: 3x1 translation vector.
#         """
#         if transform is not None:
#             self._transform = transform
#         else:
#             self._transform = scale * matrixFromEuler((rz,ry,rx),'zyx',False)
# 
#         self._inverseTransform = np.linalg.inv(self._transform)
#         self._translation = translation
# 
#     def apply(self,v):
#         """
#         Apply transform to an array of column vectors.
#         """
#         return np.tensordot(self._transform, v, axes=([1],[0])) \
#                 + self._translation
# 
#     def reverse(self,v):
#         """
#         Apply the inverse of this transform to an array of column vectors.
#         """
#         return np.tensordot(self._inverseTransform,
#                 v-self._translation,axes=([1],[0]))


# Path: imusim/tests/maths/transforms_test.py
import numpy as np
from numpy import random
from scipy import stats
from numpy import testing
from imusim.maths import transforms
from imusim.maths.vectors import vector
from imusim.maths.quaternions import Quaternion
from imusim.maths.transforms import AffineTransform
from math import sqrt

# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IMUSim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with IMUSim.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import division

RANDOM_SEED=0

def assert_almost_equal(a, b):
    for ai, bi in zip(a, b):
        testing.assert_almost_equal(ai, bi)

# each element of the list is a tuple of cartesian and polar co-ords
CARTESIAN_POLAR_TEST_VALUES = [
        ((0,0),(0,0)),
        ((0,1),(1,np.pi/2)),
        ((1,0),(1,0)),
        ((1/sqrt(2), 1/sqrt(2)), (1,np.pi/4)),
        ((0,10),(10,np.pi/2)),
        ((5,0),(5,0))
        ]
def checkPolarToCartesian(cartesian, polar):

    assert_almost_equal(transforms.polarToCartesian(*polar), cartesian)