# Path: sloth/math/rotmatrix.py
# def rotate(arr, axis, theta, method="numpy"):
#     """ rotate array around axis by theta with 'numpy' or 'weave'
# 
#     Arguments
#     ---------
#     arr : np.array([x,y,z])
#     axis : np.array([x,y,z])
#     theta : in radians
#     method : 'numpy' or 'weave'
# 
#     Returns
#     -------
#     np.array([x,y,z])
# 
#     """
#     if method == "numpy":
#         return np.dot(rotation_matrix_numpy(axis, theta), arr)
#     elif method == "weave":
#         return np.dot(rotation_matrix_weave(axis, theta), arr)
#     else:
#         raise NameError("method for rotation matrix is 'numpy' or 'weave'")


import sys, os, math
import numpy as np
from ..math.rotmatrix import rotate
    """Rowland circle horizontal frame: sample-analyser on XY plane along
Y axis

    """

    def __init__(self, *args, **kws):
        """RowlandCircle init """
        RowlandCircle.__init__(self, *args, **kws)

    def get_det_pos(self):
        """detector position [X,Y,Z]"""
        yDet = self.p + self.q * math.cos(2 * self.rtheta0)
        zDet = self.q * math.sin(2 * self.rtheta0)
        return np.array([0, yDet, zDet])

    def get_ana_pos(self, chi=0.):
        """analyser XYZ center position for a given chi

        Parameters
        ==========
        
        chi : float, 0. [deg]
              rotation angle on the sagittal plane (around sample-detector axis)
        
        """
        Acen = np.array([0, self.q, 0])
        if (chi == 0.):
            return Acen
        else:
            SDax = self.get_det_pos() - self.sampPos

# Path: sloth/math/rotmatrix.py
# def rotate(arr, axis, theta, method="numpy"):
#     """ rotate array around axis by theta with 'numpy' or 'weave'
# 
#     Arguments
#     ---------
#     arr : np.array([x,y,z])
#     axis : np.array([x,y,z])
#     theta : in radians
#     method : 'numpy' or 'weave'
# 
#     Returns
#     -------
#     np.array([x,y,z])
# 
#     """
#     if method == "numpy":
#         return np.dot(rotation_matrix_numpy(axis, theta), arr)
#     elif method == "weave":
#         return np.dot(rotation_matrix_weave(axis, theta), arr)
#     else:
#         raise NameError("method for rotation matrix is 'numpy' or 'weave'")


# Path: sloth/inst/rowland.py
import sys, os, math
import numpy as np
from ..math.rotmatrix import rotate

    """Rowland circle horizontal frame: sample-analyser on XY plane along
Y axis

    """

    def __init__(self, *args, **kws):
        """RowlandCircle init """
        RowlandCircle.__init__(self, *args, **kws)

    def get_det_pos(self):
        """detector position [X,Y,Z]"""
        yDet = self.p + self.q * math.cos(2 * self.rtheta0)
        zDet = self.q * math.sin(2 * self.rtheta0)
        return np.array([0, yDet, zDet])

    def get_ana_pos(self, chi=0.):
        """analyser XYZ center position for a given chi

        Parameters
        ==========
        
        chi : float, 0. [deg]
              rotation angle on the sagittal plane (around sample-detector axis)
        
        """
        Acen = np.array([0, self.q, 0])
        if (chi == 0.):
            return Acen
        else:
            SDax = self.get_det_pos() - self.sampPos

            Aside = rotate(Acen, SDax, math.radians(chi))