Exemple #1
0
def boxCross(disk):
    o = Options()
    additiionalEmptiness = max(
        o.getProperty('maxh_f'),  # t oavoid errors
        o.getProperty('maxh_sh'),  # in netgen nesh
        o.getProperty('maxh_m'))  # generation
    length = o.getProperty('cubeEdgeLength')
    c = disk.c()
    tc = disk.tc()
    bc = disk.bc()
    r = disk.r()
    h = disk.h()
    v = len(disk.facets())
    vtb = Vector(bc, tc)
    responce = ''
    for facet in disk.facets():
        vToFacet = facet - c
        vInFacet = vtb.vectorMultiply(vToFacet)
        realLength = vInFacet.l()
        needLength = r * math.tan(math.pi / v)
        vInFacet = vInFacet * (needLength / realLength)
        x4 = facet + vInFacet + vtb / 2
        x5 = facet - vInFacet + vtb / 2
        x6 = facet + vInFacet - vtb / 2
        x7 = facet - vInFacet - vtb / 2
        if additiionalEmptiness > x4.x() or x5.x() < additiionalEmptiness:
            return True
        if additiionalEmptiness > x6.x() or x7.x() < additiionalEmptiness:
            return True
        if additiionalEmptiness > x4.y() or x5.y() < additiionalEmptiness:
            return True
        if additiionalEmptiness > x6.y() or x7.y() < additiionalEmptiness:
            return True
        if additiionalEmptiness > x4.z() or x5.z() < additiionalEmptiness:
            return True
        if additiionalEmptiness > x6.z() or x7.z() < additiionalEmptiness:
            return True
        if x4.x() > length - additiionalEmptiness or\
           x5.x() > length - additiionalEmptiness:
            return True
        if x4.y() > length - additiionalEmptiness or\
           x5.y() > length - additiionalEmptiness:
            return True
        if x4.z() > length - additiionalEmptiness or\
           x5.z() > length - additiionalEmptiness:
            return True
        if x6.x() > length - additiionalEmptiness or\
           x7.x() > length - additiionalEmptiness:
            return True
        if x6.y() > length - additiionalEmptiness or\
           x7.y() > length - additiionalEmptiness:
            return True
        if x6.z() > length - additiionalEmptiness or\
           x7.z() > length - additiionalEmptiness:
            return True
    return False
Exemple #2
0
def disksCross(disk1, disk2):
    o = Options()
    epsilon = o.getProperty('roughEpsilon')
    c1 = disk1.c()
    tc1 = disk1.tc()
    bc1 = disk1.bc()
    c2 = disk2.c()
    dc12 = c1 - c2
    l = dc12.l()
    r = disk1.r()
    h = disk1.h()
    v = len(disk1.facets())
    if 2 * (r**2 + h**2 / 4)**0.5 < l**0.5:
        return False
    elif h > l:
        return True
    # http://mathworld.wolfram.com/Line-PlaneIntersection.html
    # facet of disk2 and top or bottom of disk1
    vtb1 = Vector(bc1, tc1)
    tc2 = disk2.tc()
    bc2 = disk2.bc()
    vtb2 = Vector(bc2, tc2)
    for (x1, x2, x3) in [
        (
            c1 + vtb1 / 2,  # top
            disk1.facets()[0] + vtb1 / 2,
            disk1.facets()[1] + vtb1 / 2),
        (
            c1 - vtb1 / 2,  # bottom
            disk1.facets()[0] - vtb1 / 2,
            disk1.facets()[1] - vtb1 / 2)
    ]:
        v12 = Vector(x2, x1)
        v32 = Vector(x2, x3)
        for facet in disk2.facets():
            vToFacet = Vector(c2, facet)
            vInFacet = vtb2.vectorMultiply(vToFacet)
            realLength = vInFacet.l()
            needLength = r * math.tan(math.pi / v)
            vInFacet = vInFacet * (needLength / realLength)
            for (x4, x5) in [
                (
                    facet + vInFacet + vtb2 / 2,  # top edge
                    facet - vInFacet + vtb2 / 2),
                (
                    facet + vInFacet - vtb2 / 2,  # bottom edge
                    facet - vInFacet - vtb2 / 2)
            ]:
                v42 = Vector(x2, x4)
                v52 = Vector(x2, x5)
                det1 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v42.x(), v42.y(), v42.z()]]))
                det2 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v52.x(), v52.y(), v52.z()]]))
                if -epsilon < det1 < epsilon or -epsilon < det2 < epsilon:
                    l = ((r / math.cos(math.pi / v))**2 + h**2 / 4)**0.5
                    if Vector(x1, x4).l() < r / math.cos(math.pi / v):
                        return True
                    if Vector(x1, x5).l() < r / math.cos(math.pi / v):
                        return True
                    #return True
                elif det1 * det2 < -epsilon:
                    v45 = Vector(x4, x5)
                    pti = x4 + v45 * abs(det1) / (abs(det1) + abs(det2))
                    if Vector(x1, pti).l() < r:
                        return True

    for facet1 in disk1.facets():
        x1 = facet1
        vToFacet1 = Vector(x1, c1)
        vInFacet1 = vtb1.vectorMultiply(vToFacet1)
        needLength = r * math.tan(math.pi / v)
        realLength = vInFacet1.l()
        vInFacet *= needLength / realLength
        x2 = x1 + vInFacet + vtb1 / 2
        x3 = x1 - vInFacet + vtb1 / 2
        v12 = Vector(x2, x1)
        v32 = Vector(x2, x3)
        for facet2 in disk2.facets():
            vToFacet = Vector(c2, facet)
            vInFacet = vtb2.vectorMultiply(vToFacet)
            realLength = vInFacet.l()
            needLength = r * math.tan(math.pi / v)
            vInFacet = vInFacet * (needLength / realLength)
            for (x4, x5) in [
                (
                    facet + vInFacet + vtb2 / 2,  # top edge
                    facet - vInFacet + vtb2 / 2),
                (
                    facet + vInFacet - vtb2 / 2,  # bottom edge
                    facet - vInFacet - vtb2 / 2)
            ]:
                v42 = Vector(x4, x2)
                v52 = Vector(x5, x2)
                det1 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v42.x(), v42.y(), v42.z()]]))
                det2 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v52.x(), v52.y(), v52.z()]]))
                if -epsilon < det1 < epsilon:
                    xi = x4
                    vectori = Vector(x1, xi)
                    cos = (abs(vectori.x() * vtb1.x() +
                               vectori.y() * vtb1.y() + vectori / z() * vtb1 /
                               z())) / vectori.l() / vtb1.l()
                    sin = (1 - cos**2)**0.5
                    axelen = cos * vectori.l()
                    norlen = sin * vectori.l()
                    if axelen < (vtb1 / 2).l() and norlen < needLength:
                        return True
                elif -epsilon < det2 < epsilon:
                    xi = x5
                    vectori = Vector(x1, xi)
                    cos = (abs(vectori.x() * vtb1.x() +
                               vectori.y() * vtb1.y() + vectori / z() * vtb1 /
                               z())) / vectori.l() / vtb1.l()
                    sin = (1 - cos**2)**0.5
                    axelen = cos * vectori.l()
                    norlen = sin * vectori.l()
                    if axelen < (vtb1 / 2).l() and norlen < needLength:
                        return True
                elif det1 * det2 < -epsilon:
                    xi = x4 + Vector(
                        x4, x5) * (abs(det1)) / (abs(det1) + abs(det2))
                    vectori = Vector(x1, xi)
                    cos = (abs(vectori.x() * vtb1.x() +
                               vectori.y() * vtb1.y() + vectori / z() * vtb1 /
                               z())) / vectori.l() / vtb1.l()
                    sin = (1 - cos**2)**0.5
                    axelen = cos * vectori.l()
                    norlen = sin * vectori.l()
                    if axelen < (vtb1 / 2).l() and norlen < needLength:
                        return True
    return False
Exemple #3
0
def boxCrossByDiskInTheShell(disk):
    o = Options()
    length = o.getProperty('cubeEdgeLength')
    c = disk.c()
    s = o.getProperty('shellThickness')
    tc = disk.tc()
    bc = disk.bc()
    r = disk.r()
    h = disk.h()
    v = len(disk.facets())
    vtb = Vector(bc, tc)
    vtb = vtb * (2 * s + h) / h
    responce = [0 for i in range(6)]
    for facet in disk.facets():
        ifcrossx = False
        ifcrossy = False
        ifcrossz = False
        ptOnFacet = c + (facet - c) / r * (r + s)
        vToFacet = facet - c
        vInFacet = vtb.vectorMultiply(vToFacet)
        realLength = vInFacet.l()
        needLength = (r + s) * math.tan(math.pi / v)
        vInFacet = vInFacet * (needLength / realLength)
        x1 = ptOnFacet + vInFacet + vtb / 2
        x2 = ptOnFacet + vInFacet - vtb / 2
        x3 = ptOnFacet - vInFacet + vtb / 2
        x4 = ptOnFacet - vInFacet - vtb / 2
        if x1.x() * x2.x() < 0 or x1.x() * x3.x() < 0 or x1.x() * x4.x() < 0:
            ifcrossx = True
        if (x1.x() - length) * (x2.x() - length) < 0 or\
           (x1.x() - length) * (x3.x() - length) < 0 or\
           (x1.x() - length) * (x4.x() - length) < 0:
            ifcrossx = True
        if x1.y() * x2.y() < 0 or x1.y() * x3.y() < 0 or x1.y() * x4.y() < 0:
            ifcrossy = True
        if (x1.y() - length) * (x2.y() - length) < 0 or\
           (x1.y() - length) * (x3.y() - length) < 0 or\
           (x1.y() - length) * (x4.y() - length) < 0:
            ifcrossy = True
        if x1.z() * x2.z() < 0 or x1.z() * x3.z() < 0 or x1.z() * x4.z() < 0:
            ifcrossz = True
        if (x1.z() - length) * (x2.z() - length) < 0 or\
           (x1.z() - length) * (x3.z() - length) < 0 or\
           (x1.z() - length) * (x4.z() - length) < 0:
            ifcrossz = True
        if ifcrossx and not ifcrossy and not ifcrossz:
            if 0 < c.y() < length and 0 < c.z() < length:
                return True
        if ifcrossy and not ifcrossx and not ifcrossz:
            if 0 < c.x() < length and 0 < c.z() < length:
                return True
        if ifcrossz and not ifcrossy and not ifcrossx:
            if 0 < c.y() < length and 0 < c.x() < length:
                return True
        if ifcrossx and ifcrossy and not ifcrossz:
            if 0 < c.z() < length:
                return True
        if ifcrossx and ifcrossz and not ifcrossy:
            if 0 < c.y() < length:
                return True
        if ifcrossz and ifcrossy and not ifcrossx:
            if 0 < c.x() < length:
                return True
        if ifcrossx and ifcrossy and ifcrossz:
            return True
    return False
Exemple #4
0
def diskDiskInTheShellCross(disk1, disk2):
    o = Options()
    epsilon = o.getProperty('roughEpsilon')
    s = o.getProperty('shellThickness')
    c1 = disk1.c()
    tc1 = disk1.tc()
    bc1 = disk1.bc()
    c2 = disk2.c()
    dc12 = c1 - c2
    l = dc12.l()
    r = disk1.r()
    h = disk1.h()
    v = len(disk1.facets())
    if 2 * (r**2 + (h / 2 + 2 * s)**2)**0.5 < l:
        return False
    elif h + 2 * s > l:
        return True
    # facet of disk2 and top of disk1
    vtb1 = Vector(bc1, tc1)
    vtb1 = vtb1 * (2 * s + h) / h
    tc2 = disk2.tc()
    bc2 = disk2.bc()
    vtb2 = Vector(bc2, tc2)
    for (x1, x2, x3) in [
        (
            c1 + vtb1 / 2,  # top
            disk1.facets()[0] + vtb1 / 2,
            disk1.facets()[1] + vtb1 / 2),
        (
            c1 - vtb1 / 2,  # bottom
            disk1.facets()[0] - vtb1 / 2,
            disk1.facets()[1] - vtb1 / 2)
    ]:
        v12 = Vector(x2, x1)
        v32 = Vector(x2, x3)
        for facet in disk2.facets():
            vToFacet = Vector(c2, facet)
            vInFacet = vtb2.vectorMultiply(vToFacet)
            realLength = vInFacet.l()
            needLength = r * math.tan(math.pi / v)
            vInFacet = vInFacet * (needLength / realLength)
            for (x4, x5) in [
                (
                    facet + vInFacet + vtb2 / 2,  # top edge
                    facet - vInFacet + vtb2 / 2),
                (
                    facet + vInFacet - vtb2 / 2,  # bottom edge
                    facet - vInFacet - vtb2 / 2)
            ]:
                v42 = Vector(x2, x4)
                v52 = Vector(x2, x5)
                det1 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v42.x(), v42.y(), v42.z()]]))
                det2 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v52.x(), v52.y(), v52.z()]]))
                if -epsilon < det1 < epsilon or -epsilon < det2 < epsilon:
                    l = ((r / math.cos(math.pi / v))**2 + h**2 / 4)**0.5
                    if Vector(x1, x4).l() < r / math.cos(math.pi / v):
                        return True
                    if Vector(x1, x5).l() < r / math.cos(math.pi / v):
                        return True
                elif det1 < -epsilon:
                    v45 = Vector(x4, x5)
                    pti = x4 + v45 * abs(det1) / (abs(det1) + abs(det2))
                    if Vector(x1, pti).l() < r:
                        return True
    return False
Exemple #5
0
def disksInTheShellCross(disk1, disk2):
    o = Options()
    epsilon = o.getProperty('roughEpsilon')
    s = o.getProperty('shellThickness')
    length = o.getProperty('cubeEdgeLength')
    h = o.getProperty('polygonalDiskThickness')
    v = o.getProperty('verticesNumber')
    r = o.getProperty('polygonalDiskRadius')

    c1 = disk1.c()
    c2 = disk2.c()

    vtb1 = Vector(disk1.bc(), disk1.tc())
    vtb1 *= (2 * s + h) / h
    vtb2 = Vector(disk2.bc(), disk2.tc())
    vtb2 *= (2 * s + h) / h

    # facet of disk2 and top/bottom of disk1:
    for [x1, x2, x3] in [[
            c1 + vtb1 / 2,
            disk1.facets()[0] + vtb1 / 2,
            disk1.facets()[1] + vtb1 / 2
    ],
                         [
                             c1 - vtb1 / 2,
                             disk1.facets()[0] - vtb1 / 2,
                             disk1.facets()[1] - vtb1 / 2
                         ]]:
        v12 = Vector(x2, x1)
        v32 = Vector(x2, x3)
        for facet2 in disk2.facets():
            vToFacet = Vector(facet2, c2)
            vToFacet *= (s + r) / r
            vInFacet = vToFacet.vectorMultiply(vtb2)
            realLength = vInFacet.l()
            needLength = (r + s) * math.tan(math.pi / v)
            vInFacet *= needLength / realLength
            for [x4, x5] in [[
                    c2 + vToFacet + vtb2 / 2 + vInFacet,
                    c2 + vToFacet + vtb2 / 2 - vInFacet
            ],
                             [
                                 c2 + vToFacet - vtb2 / 2 + vInFacet,
                                 c2 + vToFacet - vtb2 / 2 - vInFacet
                             ],
                             [
                                 c2 + vToFacet + vtb2 / 2 + vInFacet,
                                 c2 + vToFacet - vtb2 / 2 + vInFacet
                             ],
                             [
                                 c2 + vToFacet + vtb2 / 2 - vInFacet,
                                 c2 + vToFacet - vtb2 / 2 - vInFacet
                             ]]:
                v42 = Vector(x2, x4)
                v52 = Vector(x2, x5)
                det1 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v42.x(), v42.y(), v42.z()]]))
                det2 = np.linalg.det(
                    np.array([[v12.x(), v12.y(), v12.z()],
                              [v32.x(), v32.y(), v32.z()],
                              [v52.x(), v52.y(), v52.z()]]))
                if abs(det1) < epsilon:
                    if Vector(x4, x1).l() < r + s:
                        return True
                elif abs(det2) < epsilon:
                    if Vector(x5, x1).l() < r + s:
                        return True
                elif det1 * det2 < 0:
                    tmpVector = Vector(
                        x4, x5) * abs(det1) / (abs(det1) + abs(det2))
                    if Vector(x1, x4 + tmpVector).l() < r + s:
                        return True

    return False