Sector matrix in X

    :param theta: bend angle, in [rad]
    :param rho: bend radius, in [m]
    :return: 2x2 numpy array
1983
def funTransSectX(theta, rho):
    
    return np.matrix([[np.cos(theta), rho * np.sin(theta)], [-np.sin(theta) / rho, np.cos(theta)]], dtype=np.double)
902816
def to_proper_radians(theta):
    
    if theta > pi or theta < -pi:
        theta = theta % pi
    return theta
1088788
def mass_2d(self, r, rho0, gamma):
        
        alpha = np.sqrt(np.pi) * special.gamma(1. / 2 * (-1 + gamma)) / special.gamma(gamma / 2.) * r ** (2 - gamma)/(3 - gamma) *np.pi * 2 * rho0
        mass_2d = alpha*r
        return mass_2d
830137
def rotate(f,x,theta=0):
    '''
    
    '''
    f_R = lambda b: f(np.array([[x*np.cos(theta)-b*np.sin(theta)],
                                [x*np.sin(theta)+b*np.cos(theta)]]))
    return f_R
1226518
def spin_in_roche(s, etheta, elongan, eincl):
  
  #  m = Rz(long).Rx(-incl).Rz(theta).Rz(pi)
  m = euler_trans_matrix(etheta, elongan, eincl)

  return np.dot(m.T, s)
517503
def rotation_matrix(self):
        
        v, theta = self.v_theta
        c = np.cos(theta)
        s = np.sin(theta)

        return np.array([[v[0] * v[0] * (1. - c) + c,
                          v[0] * v[1] * (1. - c) - v[2] * s,
                          v[0] * v[2] * (1. - c) + v[1] * s],
                         [v[1] * v[0] * (1. - c) + v[2] * s,
                          v[1] * v[1] * (1. - c) + c,
                          v[1] * v[2] * (1. - c) - v[0] * s],
                         [v[2] * v[0] * (1. - c) - v[1] * s,
                          v[2] * v[1] * (1. - c) + v[0] * s,
                          v[2] * v[2] * (1. - c) + c]])
191849
def angle(v1, v2):
    """"""
    v1_u = unit_vector(v1)
    v2_u = unit_vector(v2)
    return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))
1174972
def rotation_matrix_2D(th):
    '''
    
    '''
    s = np.sin(th)
    c = np.cos(th)
    return np.array([[c, -s], [s, c]])
1352597
def symbolic_rotation_matrix(phi, theta, symbolic_psi):
    """"""
    return sympy.Matrix(Rz_matrix(phi)) * sympy.Matrix(Rx_matrix(theta)) * symbolic_Rz_matrix(symbolic_psi)
738515
def radius(self, angle):
        

        return (self.sma * (1. - self.eps) /
                np.sqrt(((1. - self.eps) * np.cos(angle))**2 +
                        (np.sin(angle))**2))
365773
def R_r(self, r):
        
        phi = np.random.uniform(0, 2*np.pi)
        theta = np.random.uniform(0, np.pi)
        x = r * np.sin(theta) * np.cos(phi)
        y = r * np.sin(theta) * np.sin(phi)
        R = np.sqrt(x**2 + y**2)
        return R, x, y
1011811
def function(self, x, y, kappa_ext, ra_0=0, dec_0=0):
        
        theta, phi = param_util.cart2polar(x - ra_0, y - dec_0)
        f_ = 1./2 * kappa_ext * theta**2
        return f_
825631
def rotation_matrix_from_axis_and_angle(u, theta):
    ''''''
    
    x = u[0]
    y = u[1]
    z = u[2]
    s = np.sin(theta)
    c = np.cos(theta)
    
    return np.array([[c + x**2 * (1 - c), x * y * (1 - c) - z * s, x * z * (1 - c) + y * s],
                     [y * x * (1 - c) + z * s, c + y**2 * (1 - c), y * z * (1 - c) - x * s ],
                     [z * x * (1 - c) - y * s, z * y * (1 - c) + x * s, c + z**2 * (1 - c) ]])
911154
def rotation_df(ATT):
    ''''''
    r = Matrix3()
    r.from_euler(radians(ATT.Roll), radians(ATT.Pitch), radians(ATT.Yaw))
    return r
694892
def Rz_matrix(theta):
    """"""
    return np.array([
        [np.cos(theta), -np.sin(theta), 0],
        [np.sin(theta), np.cos(theta), 0],
        [0, 0, 1]
    ])
139685
def R_rot_3d(th):
    
    sx, sy, sz = np.sin(th).T
    cx, cy, cz = np.cos(th).T
    R = np.empty((len(th), 3, 3), dtype=np.float)

    R[:, 0, 0] = cy * cz
    R[:, 0, 1] = -cy * sz
    R[:, 0, 2] = sy

    R[:, 1, 0] = sx * sy * cz + cx * sz
    R[:, 1, 1] = -sx * sy * sz + cx * cz
    R[:, 1, 2] = -sx * cy

    R[:, 2, 0] = -cx * sy * cz + sx * sz
    R[:, 2, 1] = cx * sy * sz + sx * cz
    R[:, 2, 2] = cx * cy
    return R
20971
def transFringe(beta=None, rho=None):
    
    m = np.eye(6, 6, dtype=np.float64)
    if None in (beta, rho):
        print("warning: 'theta', 'rho' should be positive float numbers.")
        return m
    else:
        m[1, 0] = np.tan(beta) / rho
        m[3, 2] = -np.tan(beta) / rho
        return m