Exemple #1
0
def iterbending2(niter, cacah, x, y, vxyz, xs, ys, xr, yr, dvx, dvy):

    xi = [xr, xs]
    yi = [yr, ys]

    if xr != xs:
        xi = np.linspace(xi[0], xi[1], cacah + 1)
    else:
        xi = np.ones(cacah + 1) * xr
    if yr != ys:
        yi = np.linspace(yi[0], yi[1], cacah + 1)
    else:
        yi = np.ones(cacah + 1) * yr

    xb = np.zeros(len(xi))
    yb = np.zeros(len(xi))

    xa = xi
    ya = yi

    for j in range(niter):
        # print(j)
        xa = xi
        ya = yi
        # print(min(xi), max(xi), min(yi), max(yi))
        if ((np.min(yi) >= np.min(y) and np.max(yi) <= np.max(y))
                and (np.min(xi) >= np.min(x) and np.max(xi) <= np.max(x))):
            for i in range(cacah - 1):
                x1 = xi[i]
                y1 = yi[i]
                x2 = xi[i + 2]
                y2 = yi[i + 2]
                xmid = bs.mid(x1, x2)
                ymid = bs.mid(y1, y2)
                o, p = bs.index(x, y, x1, y1)
                if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                    dvxi = dvx[p, o]
                    dvyi = dvy[p, o]
                    V1 = vxyz[p, o]
                else:
                    return xi, yi
                o, p = bs.index(x, y, x2, y2)
                if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                    V2 = vxyz[p, o]
                else:
                    return xi, yi
                o, p = bs.index(x, y, xmid, ymid)
                if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                    dvxm = dvx[p, o]
                    dvym = dvy[p, o]
                    Vmid = vxyz[p, o]
                else:
                    return xi, yi
                xn, yn = ray.rayBending(x1, y1, x2, y2, dvxi, dvyi, xmid, ymid,
                                        dvxm, dvym, Vmid, V1, V2)
                if np.isnan(xn) == False and np.isnan(yn) == False:
                    o, p = bs.index(x, y, xn, yn)
                    if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                        xb[i + 1] = xn
                        yb[i + 1] = yn
                    else:
                        return xi, yi
                else:
                    return xi, yi

            xb[0] = xi[0]
            yb[0] = yi[0]
            xb[-1] = xi[-1]
            yb[-1] = yi[-1]
            # print(min(yb), min(y), max(yb), max(y), min(xb), min(x), max(xb), max(x))
            # print((min(yb) >= min(y) and max(yb) <= max(y)) and (min(xb) >= min(x) and max(xb) <= max(x)))
            # if ((min(yb) >= min(y) and max(yb) <= max(y)) and (min(xb) >= min(x) and max(xb) <= max(x))):
            # print('True')
            xi = xb
            yi = yb
            # xi = np.linspace(min(y), max(x), cacah + 1)
            # yi = np.linspace(min(y), max(y), cacah + 1)
            # print(min(xi), max(xi), min(yi), max(yi))
        # else:
        # #     xi = xa
        # #     yi = ya
        #     return xi, yi

    return xi, yi
Exemple #2
0
def iterbending(niter, cacah, x, y, vxyz, xs, ys, xr, yr, dvx, dvy):
    xi = [xr, xs]
    yi = [yr, ys]

    if xr != xs:
        xi = np.linspace(xi[0], xi[1], cacah + 1)
    else:
        xi = np.ones(cacah + 1) * xr
    if yr != ys:
        yi = np.linspace(yi[0], yi[1], cacah + 1)
    else:
        yi = np.ones(cacah + 1) * yr

    xb = np.zeros(len(xi))
    yb = np.zeros(len(xi))

    xa = xi
    ya = yi

    j = 0

    while (j < niter
           and ((np.min(yi) >= np.min(x) and np.max(yi) <= np.max(y)) and
                (np.min(xi) >= np.min(y) and np.max(xi) <= np.max(x)))):
        # print(j)
        # print(min(xi), max(xi), min(yi), max(yi))
        xa = xi
        ya = yi
        for i in range(cacah - 1):
            x1 = xi[i]
            y1 = yi[i]
            x2 = xi[i + 2]
            y2 = yi[i + 2]
            xmid = bs.mid(x1, x2)
            ymid = bs.mid(y1, y2)
            o, p = bs.index(x, y, x1, y1)
            if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                dvxi = dvx[p, o]
                dvyi = dvy[p, o]
                V1 = vxyz[p, o]
            else:
                return xa, ya
            o, p = bs.index(x, y, x2, y2)
            if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                V2 = vxyz[p, o]
            else:
                return xa, ya
            o, p = bs.index(x, y, xmid, ymid)
            if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                dvxm = dvx[p, o]
                dvym = dvy[p, o]
                Vmid = vxyz[p, o]
            else:
                return xa, ya
            xn, yn = ray.rayBending(x1, y1, x2, y2, dvxi, dvyi, xmid, ymid,
                                    dvxm, dvym, Vmid, V1, V2)
            if np.isnan(xn) == False and np.isnan(yn) == False:
                o, p = bs.index(x, y, xn, yn)
                if p < len(dvx[:, 0]) and o < len(dvx[0, :]):
                    xb[i + 1] = xn
                    yb[i + 1] = yn
                else:
                    return xa, ya
            else:
                return xa, ya

        xb[0] = xi[0]
        yb[0] = yi[0]
        xb[-1] = xi[-1]
        yb[-1] = yi[-1]

        # xa = xi
        # ya = yi

        xi = xb
        yi = yb
        # print(min(xi), max(xi), min(yi), max(yi))

        j = j + 1

    return xa, ya
def iterbending(niter,cacah,x,y,vxyz,xs,ys,xr,yr,dvx,dvy):

    xi = [xr, xs]
    yi = [yr, ys]

    if xr != xs:
        xi = np.linspace(xi[0], xi[1], cacah + 1)
    else:
        xi = np.ones(cacah+1)*xr
    if yr != ys:
        yi = np.linspace(yi[0], yi[1], cacah + 1)
    else:
        yi = np.ones(cacah+1)*yr

    xb = np.zeros(len(xi))
    yb = np.zeros(len(xi))

    if niter == 0:
        return xi, yi
    else:
        for j in range(niter):
            for i in range(cacah - 1):
                x1 = xi[i]
                y1 = yi[i]
                x2 = xi[i + 2]
                y2 = yi[i + 2]
                xmid = bs.mid(x1, x2)
                ymid = bs.mid(y1, y2)
                o, p = bs.index(x, y, x1, y1)
                if p < len(dvx[:,0]) and o < len(dvx[0,:]):
                    dvxi = dvx[p, o]
                    dvyi = dvy[p, o]
                    V1 = vxyz[p, o]
                else:
                    return xi, yi
                o, p = bs.index(x, y, x2, y2)
                if p < len(dvx[:,0]) and o < len(dvx[0,:]):
                    V2 = vxyz[p, o]
                else:
                    return xi, yi
                o, p = bs.index(x, y, xmid, ymid)
                if p < len(dvx[:,0]) and o < len(dvx[0,:]):
                    dvxm = dvx[p, o]
                    dvym = dvy[p, o]
                    Vmid = vxyz[p, o]
                else:
                    return xi, yi
                xn, yn = ray.rayBending(x1, y1, x2, y2, dvxi, dvyi, xmid, ymid, dvxm, dvym,
                                             Vmid,V1, V2)
                if np.isnan(xn) == False and np.isnan(yn) == False:
                    o, p = bs.index(x, y, xn, yn)
                    if p < len(dvx[:,0]) and o < len(dvx[0,:]):
                        xb[i + 1] = xn
                        yb[i + 1] = yn
                    else:
                        return xi, yi
                else:
                    return xi, yi

            xb[0] = xi[0]
            yb[0] = yi[0]
            xb[-1] = xi[-1]
            yb[-1] = yi[-1]
            if min(yb) >= min(yi) and max(yb) <= max(yi):
                xi = xb
                yi = yb
            else:
                return xi, yi
    return xi,yi