Example #1
0
def ring_patch(rin, rout, inc_deg, tilt_deg, tau, dr=([0, 0])):
    ''' 
    this function makes a Patch in the shape of a tilted annulus
    
    Parameters
    ----------
    rin : float
        inner radius of the annulus
    rout : float
        outer radius of the annulus
    inc_deg : float
        inclination of the annulus in degrees
    tilt_deg : float
        tilt of the annulus (w.r.t. x-axis) in degress
    tau : float
        opacity of the annulus
    dr : tuple:
        (x,y) centre of the annulus
    
    Returns
    -------
    newP : matplotlib.patch
        path object to be added to figures
    '''
    # conversion to radians
    inc = np.deg2rad(inc_deg)
    tilt = np.deg2rad(tilt_deg)
    # get an Ellipse patch that has an ellipse defined with eight CURVE4 Bezier
    # curves actual parameters are irrelevant - get_path() returns only a
    # normalised Bezier curve ellipse which we then subsequently transform
    e1 = Ellipse((1, 1), 1, 1, 0)
    # get the Path points for the ellipse (8 Bezier curves with 3 additional
    # control points)
    e1p = e1.get_path()
    # create a rotation matrix
    c = np.cos(tilt)
    s = np.sin(tilt)
    rotm = np.array([[c, s], [s, -c]])
    # transform the vertices
    i = np.cos(inc)
    a1 = e1p.vertices * ([1., i])
    a2 = e1p.vertices * ([-1., i])
    e1r = np.dot(a1 * rout, rotm) + dr
    e2r = np.dot(a2 * rin, rotm) + dr
    # create the vertices and fix the path
    new_verts = np.vstack((e1r, e2r))
    new_cmds = np.hstack((e1p.codes, e1p.codes))
    newp = Path(new_verts, new_cmds)
    newP = PathPatch(newp, facecolor='black', edgecolor='none', alpha=tau)
    return newP