Esempio n. 1
0
def calc_truncated_g(org_solid):
    #org = mid_truncated_solid2org_solid[solid]
    org_g = Platonic_solid2g[org_solid]

    n = org_solid[0]  # n-gon face of org_solid
    angle = angle_of_regular_polygon(n)

    # assume org_L = 2; 1 = org_L/2
    org_L = 2 * one
    org_L, X = symbols('org_L X', positive=True)
    new_L = opposite_tri_edge(org_L, angle, org_L) * X
    new_L_ = org_L * (1 - 2 * X)
    x, = solve(new_L - new_L_, X)
    x = my_sympify(x)
    new_L = my_sympify(new_L.subs(X, x))

    org_R = org_L / org_g
    org_Rc = outer_radius_of_regular_polygon(n, org_L)
    org_rc = inner_radius_of_regular_polygon(n, org_L)
    org_HH = org_R**2 - org_Rc**2

    new_rc_rc = org_rc**2 + (new_L / 2)**2
    new_RR = org_HH + new_rc_rc
    new_R = sqrt(new_RR)

    new_g = new_L / new_R
    g = my_sympify(new_g)
    g = nsimplify(g)

    if not g.is_number:
        print(locals())
    assert g.is_number
    return g
Esempio n. 2
0
def calc_mid_truncated_g(org_solid):
    #org = mid_truncated_solid2org_solid[solid]
    org_g = Platonic_solid2g[org_solid]

    n = org_solid[0]  # n-gon face of org_solid
    angle = angle_of_regular_polygon(n)

    # assume org_L = 2; 1 = org_L/2
    org_L = 2 * one
    org_L = symbols('org_L', positive=True)
    new_L = opposite_tri_edge(org_L, angle, org_L) / 2

    org_R = org_L / org_g
    org_Rc = outer_radius_of_regular_polygon(n, org_L)
    org_rc = inner_radius_of_regular_polygon(n, org_L)
    org_HH = org_R**2 - org_Rc**2
    new_RR = org_HH + org_rc**2
    new_R = sqrt(new_RR)

    new_g = new_L / new_R
    g = my_sympify(new_g)

    if not g.is_number:
        print(locals())
    assert g.is_number
    return g
Esempio n. 3
0
def verify_G(solid, g):
    zeroexpr = solid2zeroexpr[solid]
    G, = zeroexpr.free_symbols - {v}
    z = zeroexpr.subs(G, g)
    z = trigsimp(z)
    z = my_sympify(z)
    z = nsimplify(z)
    return 0 == z
Esempio n. 4
0
def __verify_C(A, B, angle_BAC, C):
    O = (0, 0, 0)
    OC, OB, OA = C, B, A = list(map(tuple, (C, B, A)))
    R = len_OA = len_OB = distance(O, A)
    L = len_AB = len_AC = distance(B, A)
    len_BC = opposite_tri_edge(len_AB, angle_BAC, len_AC)
    len_BC = my_sympify(len_BC)
    assert nsimplify(distance(B, C) - len_BC) == 0
    assert nsimplify(distance(A, C) - L) == 0
    assert dot_product(cross_product(OB, OA), OC) > 0
Esempio n. 5
0
def next_clockwise_edge_endpoint(A, B, angle_BAC):
    assert 0 <= angle_BAC <= pi
    O = (0, 0, 0)
    #print(list(map(type, [A,B])))
    #print(list(map(tuple, (B, A))))
    #OB, OA = B, A = map(tuple, (B, A))
    # add list. why?????????
    #
    # sympy bug: Tuple.__new__ not like tuple's!!!
    OB, OA = B, A = list(map(tuple, (B, A)))
    R = len_OA = len_OB = distance(O, A)
    L = len_AB = len_AC = distance(B, A)
    len_BC = opposite_tri_edge(len_AB, angle_BAC, len_AC)
    len_BC = my_sympify(len_BC)

    # Q on OA, BQ _L OA
    S_ABO = tri_area(len_OA, len_OB, len_AB)
    assert nsimplify(S_ABO) > 0
    len_CQ = len_BQ = one * 2 * S_ABO / len_OA
    len_CQ = len_BQ = my_sympify(len_BQ)

    angle_BQC = opposite_tri_angle(len_BQ, len_BC, len_CQ)
    angle_BQC = my_sympify(angle_BQC)
    assert nsimplify(angle_BQC) > 0
    assert nsimplify(angle_BQC - pi) < 0
    C = OC = rotate_clockwise(O, A, B, angle_BQC)
    C = OC = tuple(map(my_sympify, OC))

    ##    print(next_clockwise_edge_endpoint)
    ##    print(distance(B,C))
    ##    print(len_BC)
    try:
        assert nsimplify(distance(O, C) - R) == 0
        assert nsimplify(distance(A, C) - L) == 0
        assert nsimplify(distance(B, C) - len_BC) == 0
        assert dot_product(cross_product(OB, OA), OC) > 0
    except:
        print(locals())
        assert nsimplify(distance(O, C) - R, tolerance=0) == 0
        raise
    return tuple(C)
def sum_asin2zero_radical_expr(sorted_Cs):
    '''pi/2 == sum C[i] asin (K[i]*w) {i=0..n-1} = asin ALL
==>> ALL - 1 == 0
return ALL-1

where w = 1/sqrt(-g**2 + 4)'''

    n = len(sorted_Cs)
    assert n > 0

    Ks = symbols(' '.join('K' + str(i) for i in range(n)), positive=True)
    W = symbols('W', positive=True)

    ALL = sum_asin2one_asin(sorted_Cs, Ks, W)
    zero_expr = ALL - 1

    return my_sympify(zero_expr)
def two_asin2no_asin(sorted_Cs):
    '''pi/2 == sum C[i] asin (K[i]*w) {i=0..1} = asin ALL
==>> ALL - 1 == 0
return ALL-1

where w = 1/sqrt(-g**2 + 4)'''

    assert len(sorted_Cs) == 2

    KsW = symbols('K0 K1 W', positive=True)
    K = KsW[:-1]
    W = KsW[-1]

    ALL = sum_asin2one_asin(sorted_Cs, K, W)
    zero_expr = ALL - 1

    return my_sympify(zero_expr)
    '''
Esempio n. 8
0
def calc_zero_poly_K0K1W_of_Cs_half_2():
    # sorted_Cs2solids[(1/2, 2)] == [(3, 3, 3, 3, 5), (3, 3, 3, 3, 4)]
    # solid2sorted_C_Ks:
    ## (3, 3, 3, 3, 4): ((1/2, sqrt(2)), (2, 1)),
    ## (3, 3, 3, 3, 5): ((1/2, 1/2 + sqrt(5)/2), (2, 1)),

    solid2g_k0k1 = {
        (3, 3, 3, 3, 4): (0.744206331156206, (sqrt(2), 1)),
        (3, 3, 3, 3, 5): (0.463856880645439, ((1 + sqrt(5)) / 2, 1)),
    }
    # calc x, w, y, z, t, u
    solid2info = {}
    for solid, (g, (k0, k1)) in solid2g_k0k1.items():
        gg = g * g
        xx = 4 - gg
        x = sqrt(xx)
        ww = 1 / xx
        w = sqrt(ww)
        yy = 1 - k0**2 * ww
        y = sqrt(yy)
        zz = 1 - k1**2 * ww
        z = sqrt(zz)
        tt = 1 + y
        t = sqrt(tt)
        uu = 2 - tt
        u = sqrt(uu)
        solid2info[solid] = {
            G: g,
            K0: k0,
            K1: k1,
            GG: gg,
            WW: ww,
            W: w,
            XX: xx,
            X: x,
            YY: yy,
            Y: y,
            ZZ: zz,
            Z: z,
            TT: tt,
            T: t,
            UU: uu,
            U: u,
        }
    info = solid2info[(3, 3, 3, 3, 4)]

    def ef(f):
        assert f.subs(info).is_number
        return N(abs(f.subs(info)))
        if not f.subs(info).is_number:
            print('not f.subs(info).is_number:', f, info)
            pass
        return N(abs(f.subs(info).subs(K1, info[K1])))

    tf = lambda f: ef(f) < 1e-7

    zero_angle_of_Cs_half_2 = two_asin2no_asin((one / 2, 2))
    assert zero_angle_of_Cs_half_2 == -K1**2 * W**2 * sqrt(
        -2 * sqrt(-K0**2 * W**2 + 1) + 2
    ) / 2 + sqrt(2) * K1 * W * sqrt(-K1**2 * W**2 + 1) * sqrt(
        sqrt(-K0**2 * W**2 + 1) + 1) / 2 + K1 * W * sqrt(
            -4 * K1**2 * W**2 * sqrt(-K0**2 * W**2 + 1) - 4 * K1 * W *
            sqrt(-K1**2 * W**2 + 1) * sqrt(-sqrt(-K0**2 * W**2 + 1) + 1) *
            sqrt(sqrt(-K0**2 * W**2 + 1) + 1) + 2 * sqrt(-K0**2 * W**2 + 1) +
            2) / 2 + sqrt(-2 * sqrt(-K0**2 * W**2 + 1) + 2) / 2 - 1
    # 33334: 0 == -48*asin(sqrt(2)/sqrt(-g**2 + 4)) - 192*asin(1/sqrt(-g**2 + 4)) + 48*pi
    f = zero_angle_of_Cs_half_2
    assert tf(f)

    h = f.subs(sqrt(1 - K0**2 * W**2), Y).subs(sqrt(1 - K1**2 * W**2), Z)
    assert tf(h)
    assert h.free_symbols == {Z, K1, W, Y}
    h = h.subs(Y, T * T - 1)
    assert tf(h)
    h = my_sympify(h)
    assert h.free_symbols == {Z, K1, W, T}
    _c, _h = h.as_content_primitive()
    assert _c.is_number
    # _c*_h != h
    h /= _c

    #print(h)
    h1 = -K1**2 * W**2 * sqrt(-2 * T**2 + 4) + sqrt(2) * K1 * T * W * Z + sqrt(
        -2 * T**2 + 4) - 2
    h2 = K1 * W * sqrt(-4 * K1**2 * T**2 * W**2 + 4 * K1**2 * W**2 -
                       4 * K1 * T * W * Z * sqrt(-T**2 + 2) + 2 * T**2)
    assert h == h1 + h2
    assert tf(h)
    f = h1**2 - h2**2
    f = expand(f)
    assert tf(f)

    f = f.subs(T * T, 2 - U * U)
    f = expand(f)
    h = expand(even_square_sub_odd_square(f, U, 2 - T * T))
    assert h.free_symbols == {K1, W, T, Z}
    assert tf(h)

    # remove T
    f = expand(even_square_sub_odd_square(h, T, 1 + Y))
    assert f.free_symbols == {K1, W, Y, Z}
    assert tf(f)
    h = expand(even_square_sub_odd_square(f, Y, 1 - K0**2 * W**2))
    assert h.free_symbols == {K1, W, K0, Z}
    assert tf(h)
    f = expand(even_square_sub_odd_square(h, Z, 1 - K1**2 * W**2))
    assert f.free_symbols == {K1, W, K0}
    assert tf(f)

    h = factor(f)
    assert h == 65536 * K0**8 * W**16 * (K0**2 + 64 * K1**8 * W**6 -
                                         128 * K1**6 * W**4 +
                                         80 * K1**4 * W**2 - 16 * K1**2)**4
    f = (K0**2 + 64 * K1**8 * W**6 - 128 * K1**6 * W**4 + 80 * K1**4 * W**2 -
         16 * K1**2)
    assert tf(f)
    deg = Poly(f, W).degree()
    assert deg % 2 == 0
    h = f.subs(W * W, 1 / (4 - GG)) * (4 - GG)**(deg // 2)
    h = factor(h)
    h = collect(h, GG)
    assert tf(h)
    assert h == GG**3 * (-K0**2 + 16 * K1**2) + GG**2 * (
        12 * K0**2 + 80 * K1**4 - 192 * K1**2) + GG * (
            -48 * K0**2 + 128 * K1**6 - 640 * K1**4 + 768 * K1**2
        ) + 64 * K0**2 + 64 * K1**8 - 512 * K1**6 + 1280 * K1**4 - 1024 * K1**2
    return h

    #############################
    P = sqrt(-sqrt(2) * U**2 + 4)
    f = collect(f, P)
    # fail:
    ##A, B = map(Wild, 'AB')
    ##d = (A + B*P).matches(f)
    ##assert d[A] + d[B]*P == f
    ##h = d[A]**2 - (d[B]*P)**2
    d = get_order2coeff_of(f, P)
    assert set(d) == {0, 1}
    assert d[0] + d[1] * P == f
    h = d[0]**2 - (d[1] * P)**2
    h = my_sympify(h)
    2 * cos(pi / v) / sqrt(-GG + 4)) + 4 * pi * v

4, 4, 3
Rc = 2
L = 2 * sqrt(3)
RR = 3 + 4
g = 2 * sqrt(3) / sqrt(7)
f = f44v

z = f.subs(v, 3).subs(GG, g * g)
z = nsimplify(z)
assert z == 0
x = g44v.subs(v, 3)
assert nsimplify(x - g) == 0

f = my_sympify(f44v.subs(GG, g44v**2))
#print(f)

h = 4 * v * (-2 * asin(sqrt(2) * sqrt(sin(pi / v)**2 + 1) / 2) -
             asin(sqrt(sin(pi / v)**2 + 1) * cos(pi / v)) + pi)

for i in range(3, 10):
    x = h.subs(v, i)
    x = nsimplify(x)
    assert 0 == x


from Archimedean_solid.Archimedean_solid__L_div_R_using_sympy__calc_g333v_g44v \
     import *

z = v * (-4 * asin(sqrt(sin(pi / v)**2 + 1) * cos(pi / v)) -