Ejemplo n.º 1
0
def get_deg_dim( imp_lst ):
    '''
    Parameters
    ----------
    imp_lst : list<OrbRing.R>
        A list of homogenous polynomials in QQ[x0,...,x8]
        representing a variety S in projective 8-space P^8.
    
    Returns
    -------
    int[]
        A 2-tuple of integers consisting of
        the degree and the dimension of the variety S.
    '''
    # consider ideal in ring of the right dimension.
    R = sage_PolynomialRing( sage_QQ, sage_var( 'y0,y1,y2,y3,y4,y5,y6,y7,y8' ), order = 'degrevlex' )
    I = R.ideal( sage__eval( str( imp_lst ).replace( 'x', 'y' ), R.gens_dict() ) )

    # compute Hilbert polynomial: (deg/dim!)*t^dim + ...
    hpol = I.hilbert_polynomial()

    dim = hpol.degree()

    deg = hpol
    for i in range( dim ):
        deg = deg.diff()

    OrbTools.p( 'hpol =', hpol, ' (deg, dim)=', ( deg, dim ) )

    return deg, dim
Ejemplo n.º 2
0
def get_pmz_verify( o ):
    '''
    Parameters
    ----------
        o : OrbOutput
    
    Returns
    -------
    Boolean
        * Return "None" if the test could not be performed because
          either parametrization or implicit equation was not available.            
        * Return "True" if implicit equation of projected surface
          agrees with parametrization composed with projection.          
        * Return "False" if both parametrization and implicit equation were 
          available but do not agree.               
    '''

    if not o.input.do['pmz'] or not o.input.do['imp']:
        return None

    if o.prj_pol == -1 or o.gen == -2:
        return False

    OrbTools.p( 'Testing parametrization...' )
    c0, s0, c1, s1 = OrbRing.coerce( 'c0,s0,c1,s1' )
    x0, x1, x2, x3 = OrbRing.coerce( 'x0,x1,x2,x3' )
    f = o.prj_pol
    p = o.prj_pmz_lst
    fp = o.prj_pol.subs( {x0:p[0], x1:p[1], x2:p[2], x3:p[3]} )
    test = fp.reduce( [c0 * c0 + s0 * s0 - 1, c1 * c1 + s1 * s1 - 1] )
    OrbTools.p( test )
    if test != 0:
        return False

    return True
Ejemplo n.º 3
0
def get_genus( pol, plane = 'x1+2*x2+17*x3+11*x0' ):
    '''
    The method requires that the maple-command 
    is in "os.environ['PATH']". 
    See [https://www.maplesoft.com].
    
    Parameters
    ----------
    pol : OrbRing.R
        A polynomial in QQ[x0,x1,x2,x3].
    
    plane : string 
        A String of a linear polynomial in QQ[x0,x1,x2,x3].
        
    Returns
    -------
    int
        An integer denoting the geometric genus of
        the curve given by the intersection of the 
        surface defined by "pol", with the plane defined 
        by "plane". If this geometric genus is not defined, 
        then -2 is returned. 
        If Maple is not installed then -3 is returned.
    '''
    OrbTools.p( pol )

    # obtain an equation for the curve defined
    # intersecting a plane with the zero-set of pol.
    plane = OrbRing.coerce( plane )
    K = sage_ideal( pol, plane ).groebner_basis()
    P = K[0]
    if P.total_degree() <= 1:
        P = K[1]
    P = P.subs( {OrbRing.coerce( 'x3' ):1} )

    # compute geometric genus with Maple.
    try:
        sage_maple.eval( 'with(algcurves);' )
    except:
        return -3

    sage_maple.eval( 'P := ' + str( P ) + ';' )
    gen = sage_maple.eval( 'genus(P,x1,x2);' )

    OrbTools.p( gen )

    try:
        return int( gen )
    except ValueError:
        return -2
Ejemplo n.º 4
0
def pov_raytrace(pin, pov_str):
    '''
    Parameters
    ----------
    pin : PovInput     
        The following attributes of the PovInput object are used:
        * pin.path
        * pin.fname
        * pin.width
        * pin.height
        * pin.quality
    
    pov_str : string
        A string of a povray input file.
    
    Returns
    -------
        A povray image at "pin.path + pin.fname + '.pov'". 
    '''

    # set file name
    #
    file_name = pin.path + pin.fname + '.pov'
    output_name = pin.path + pin.fname + '.png'

    # write povray string
    #
    OrbTools.p('Writing povray string to:', file_name)
    create_dir(file_name)
    with open(file_name, "w") as text_file:
        text_file.write(pov_str)

    # execute povray tracer
    #
    my_env = dict(os.environ)
    my_env['LD_LIBRARY_PATH'] = ''  # prevent problems with C++ libraries

    cmd = ['povray']
    cmd += ['+O' + output_name]
    cmd += ['+W' + str(pin.width)]
    cmd += ['+H' + str(pin.height)]
    cmd += ['+Q' + str(pin.quality)]
    if pin.quality > 5:
        cmd += ['+A']  # antialiasing
    cmd += ['-D']  # no popup window
    cmd += [file_name]

    OrbTools.p(cmd)
    p = subprocess.Popen(cmd,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         env=my_env)
    out, err = p.communicate()

    OrbTools.p('out =', out)
    OrbTools.p('err =', err)
Ejemplo n.º 5
0
def usecase_orb_product_implicit_circle(num=10):
    '''
    Outputs "num" random surfaces in the projective n-sphere S^n, 
    that are obtained by rotating or translating an implicit circle.
    The circle is obtained as a random hyperplane section.
    
    The hyperplane section is obtained by applying 
    a random matrix in PGL(8+1) to the hyperplane 
    section { x | x3=..=x8=0=-x0^2+x1^2+...+x8^2=0 }.  
    Since the random matrix is not orthogonal
    we cannot use the matrix to compute parametric 
    presentations for these examples.  
    
    Notice that we can recover the OrbInput object 
    from the short string output 
    (see "usecase_orb_product_investigate_example()")
    
    Parameters
    ----------
    num : int
        Number of times a random surface should be computed.   
    '''

    for idx in range(num):
        try:

            # compute random input
            ch_str = ''.join([
                OrbRing.random_elt(['r', 's', 'p', 'm', 'a']) for i in range(4)
            ])
            pmat = list(sage_MatrixSpace(sage_ZZ, 9, 9).random_element())
            p_tup = ('P1', 'I', 'I')
            o_tup = ('I', 'O' + ch_str, 'I')
            v_tup = ('M' + str(pmat), 'I', 'I')
            input = OrbInput().set(p_tup, o_tup, v_tup)

            # compute only few attributes
            for key in input.do.keys():
                input.do[key] = False
            input.do['imp'] = True
            input.do['dde'] = True

            o = orb_product(input)

            OrbTools.p('(deg, emb, dim ) =',
                       (o.deg, o.emb, o.dim), ' short string =',
                       o.get_short_str())  # output  orbital product

        except BaseException as e:

            # continue with loop regardless of exceptions
            OrbTools.p('Exception occurred: ', e)
            OrbTools.p(input)
            OrbTools.p(o)
Ejemplo n.º 6
0
def usecase_orb_product_investigate_example():
    '''
    Here we investigate an example obtained 
    by "usecase_orb_product"
    '''

    s = "['@(4,3)=(deg,emb)', {'pmat': ('P0', 'I', 'I'), 'omat': ('T[1, 0, 0, 0, 0, 0, 0]', 'Orppp', 'T[-1, 0, 0, 0, 0, 0, 0]'), 'vmat': ('T[0, 1, 1, 0, 0, 0, 0]', 'Rrrrs[37, 0, 0, 0]', 'T[0, -1, -1, 0, 0, 0, 0]')}]"

    input = OrbInput().set_short_str(s)
    input.do['pmz'] = True
    input.do['bpt'] = False
    input.do['imp'] = True
    input.do['dde'] = True
    input.do['prj'] = True
    input.do['fct'] = True  # requires Maple
    input.do['gen'] = True  # requires Maple
    input.do['sng'] = True  # requires Magma
    input.do['tst'] = True

    o = orb_product(input)
    OrbTools.p(o)
Ejemplo n.º 7
0
def usecase_orb_product(num=10):
    '''
    Outputs "num" random surfaces in the projective n-sphere S^n, 
    that are obtained by rotating or translating a parametrized 
    circle.
    
    Notice that we can recover the OrbInput object 
    from the short string output 
    (see "usecase_orb_product_investigate_example()")
    
    Parameters
    ----------
    num : int
        Number of times a random surface should be computed.
    '''

    for idx in range(num):
        try:

            input = OrbInput().random(3, False)  # random input

            # only compute dimension and degree
            for key in input.do.keys():
                input.do[key] = False
            input.do['imp'] = True
            input.do['dde'] = True

            o = orb_product(input)

            OrbTools.p('(deg, emb, dim ) =',
                       (o.deg, o.emb, o.dim), ' short string =',
                       o.get_short_str())  # output  orbital product

        except BaseException as e:

            # continue with loop regardless of exceptions
            OrbTools.p('Exception occurred: ', e)
            OrbTools.p(input)
            OrbTools.p(o)
Ejemplo n.º 8
0
def convert_pngs_gif( path, fname, num_curves, ani_delay ):
    '''
    Creates an animated gif file with name "[path]+[fname].gif".

    Parameters
    ---------- 
    path : string      
        Location (ending with '/') of "ani/" directory containing
        png-files with name 
            "[fname]-#.png"
        where # is a number in [0,num_curves]
    
    fname : string      
        A string. 
    
    num_curves : int 
        A positive integer.

    ani_delay : int 
        A positive integer.    
    '''
    # We now convert the ray traced images into an animated
    # gif using the following linux command:
    #
    #    convert -resize 768x576 -delay 20 -loop 0 `ls -v orb?*.png` orb-ani.gif
    #

    file_name_prefix = path + 'ani/' + fname
    OrbTools.p( file_name_prefix )
    cmd = ['convert']
    cmd += ['-delay', str( ani_delay )]
    cmd += [ '-loop', '0']
    for idx in range( 0, num_curves ):
        cmd += [file_name_prefix + '-' + str( idx ) + '.png']
    cmd += [path + fname + '.gif']

    p = subprocess.Popen( cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE )

    out, err = p.communicate()
    OrbTools.p( 'out =', out )
    OrbTools.p( 'err =', err )
Ejemplo n.º 9
0
def get_factor_lst( pol ):
    '''
    The method requires that the maple-command 
    is in "os.environ['PATH']".
    See [https://www.maplesoft.com].
    
    Parameters
    ----------
    pol : OrbRing.R  
        A polynomial.
    
    Returns
    -------
    list
        Return a list of factors of "pol": 
        [ (<factor>,<multiplicity>),... ] 
        If Maple is not accessible, then
        returns the empty-list [] 
    '''
    try:
        sage_maple.eval( 'fct := evala(AFactors(' + str( pol ) + '));' )
    except:
        return []

    fct_lst = sage_maple.eval( 'lprint(fct);' )
    fct_lst = str( fct_lst ).split( ',' )

    OrbTools.p( fct_lst )

    cf = fct_lst[0].replace( '[', '' ).replace( ']', '' ).strip()
    new_lst = []
    for i in range( 1, len( fct_lst ), 2 ):
        fact = fct_lst[i].replace( '[', '' ).replace( ']', '' ).strip()
        mult = fct_lst[i + 1].replace( '[', '' ).replace( ']', '' ).strip()
        new_lst += [( fact, mult )]

    OrbTools.p( cf )
    OrbTools.p( len( new_lst ), new_lst )

    return new_lst
Ejemplo n.º 10
0
def blum_cyclide():
    '''
    Construct a povray image of 6 families of circles on a smooth Darboux cyclide.
    This surface is also known as the Blum cyclide.
    '''

    # construct dct
    a0 = PolyRing( 'x,y,v,w', True ).ext_num_field( 't^2 + 1' ).root_gens()[0]  # i

    bpt_1234 = BasePointTree( ['xv', 'xw', 'yv', 'yw'] )
    bpt_1234.add( 'xv', ( -1 * a0, 1 * a0 ), 1 )  # e1
    bpt_1234.add( 'xv', ( 1 * a0, -1 * a0 ), 1 )  # e2
    bpt_1234.add( 'xw', ( -2 * a0, 2 * a0 ), 1 )  # e3
    bpt_1234.add( 'xw', ( 2 * a0, -2 * a0 ), 1 )  # e4

    bpt_12 = BasePointTree( ['xv', 'xw', 'yv', 'yw'] )
    bpt_12.add( 'xv', ( -1 * a0, 1 * a0 ), 1 )  # e1
    bpt_12.add( 'xv', ( 1 * a0, -1 * a0 ), 1 )  # e2

    bpt_34 = BasePointTree( ['xv', 'xw', 'yv', 'yw'] )
    bpt_34.add( 'xw', ( -2 * a0, 2 * a0 ), 1 )  # e3
    bpt_34.add( 'xw', ( 2 * a0, -2 * a0 ), 1 )  # e4

    ls_22 = LinearSeries.get( [2, 2], bpt_1234 )  # |2(l1+l2)-e1-e2-e3-e4|
    ls_21 = LinearSeries.get( [2, 1], bpt_1234 )
    ls_12 = LinearSeries.get( [1, 2], bpt_1234 )
    ls_11a = LinearSeries.get( [1, 1], bpt_12 )
    ls_11b = LinearSeries.get( [1, 1], bpt_34 )

    OrbTools.p( 'linear series 22 =\n', ls_22 )
    OrbTools.p( 'linear series 21 =\n', ls_21 )
    OrbTools.p( 'linear series 12 =\n', ls_12 )
    OrbTools.p( 'linear series 11a =\n', ls_11a )
    OrbTools.p( 'linear series 11b =\n', ls_11b )

    sig = ( 4, 1 )
    pol_lst = ls_22.get_implicit_image()

    # determine signature
    x_lst = sage_PolynomialRing( sage_QQ, [ 'x' + str( i ) for i in range( sum( sig ) )] ).gens()
    for pol in pol_lst:

        if pol.degree() == 2:
            M = sage_invariant_theory.quadratic_form( pol, x_lst ).as_QuadraticForm().matrix()
            D, V = sage_matrix( sage_QQ, M ).eigenmatrix_right()  # D has first all negative values on diagonal
            cur_sig = ( len( [ d for d in D.diagonal() if d < 0 ] ), len( [ d for d in D.diagonal() if d > 0 ] ) )
        else:
            cur_sig = '[no signature]'
        OrbTools.p( '\t\t', pol, cur_sig )

    # obtain surface in sphere
    coef_lst = [0, -1, -1]
    dct = get_surf( ls_22, sig, coef_lst )

    # construct projection matrix P
    U, J = dct['UJ']
    U.swap_rows( 0, 4 )
    J.swap_columns( 0, 4 )
    J.swap_rows( 0, 4 )
    assert dct['M'] == approx_QQ( U.T * J * U )
    approxU = approx_QQ( U )
    P = sage_identity_matrix( 5 ).submatrix( 0, 0, 4, 5 )
    P[0, 4] = -1;
    P = P * approxU
    OrbTools.p( ' approx_QQ( U ) =', list( approx_QQ( U ) ) )
    OrbTools.p( ' approx_QQ( J ) =', list( approx_QQ( J ) ) )
    OrbTools.p( ' P              =', list( P ) )

    # call get_proj
    f_xyz, pmz_AB_lst = get_proj( dct['imp_lst'], dct['pmz_lst'], P )
    f_xyz_deg_lst = [f_xyz.degree( sage_var( v ) ) for v in ['x', 'y', 'z']]

    # compute reparametrization
    ring = PolyRing( 'x,y,v,w,c0,s0,c1,s1' )  # construct polynomial ring with new generators
    p_lst = ring.coerce( ls_22.pol_lst )
    x, y, v, w, c0, s0, c1, s1 = ring.gens()
    X = 1 - s0; Y = c0;  # see get_S1xS1_pmz()
    V = 1 - s1; W = c1;
    CB_dct = { x:X, y:Y, v:X * W + Y * V, w: X * V - Y * W }
    DB_dct = { x:X, y:Y, v:4 * X * W - Y * V, w: X * V + Y * W }
    EB_dct = { x:X, y:Y, v:40 * W * X ** 2 + 25 * W * Y ** 2 + 24 * V * X * Y, w:40 * V * X ** 2 + 16 * V * Y ** 2 - 15 * W * X * Y  }
    AF_dct = { x:-10 * Y * V ** 2 - 25 * Y * W ** 2 + 9 * X * V * W, y:15 * X * V ** 2 + 24 * X * W ** 2 - 15 * Y * V * W, v:V, w:W  }
    pmz_CB_lst = list( P * sage_vector( [ p.subs( CB_dct ) for p in p_lst] ) )
    pmz_DB_lst = list( P * sage_vector( [ p.subs( DB_dct ) for p in p_lst] ) )
    pmz_EB_lst = list( P * sage_vector( [ p.subs( EB_dct ) for p in p_lst] ) )
    pmz_AF_lst = list( P * sage_vector( [ p.subs( AF_dct ) for p in p_lst] ) )


    # output
    OrbTools.p( 'f_xyz =', f_xyz_deg_lst, '\n', f_xyz )
    OrbTools.p( 'pmz_AB_lst =\n', pmz_AB_lst )
    OrbTools.p( 'pmz_CB_lst =\n', pmz_CB_lst )
    OrbTools.p( 'pmz_DB_lst =\n', pmz_DB_lst )
    OrbTools.p( 'pmz_EB_lst =\n', pmz_EB_lst )
    OrbTools.p( 'pmz_AF_lst =\n', pmz_AF_lst )

    # mathematica
    pmz_lst = [ ( pmz_AB_lst, 'AB' ),
                ( pmz_CB_lst, 'CB' ),
                ( pmz_DB_lst, 'DB' ),
                ( pmz_EB_lst, 'EB' ),
                ( pmz_AF_lst, 'AF' )]

    OrbTools.p( 'Mathematica input for ParametricPlot3D:' )
    for pmz, AB in pmz_lst:
        s = 'pmz' + AB + '=' + str( pmz )
        s = s.replace( '[', '{' ).replace( ']', '}' )
        print( s )

    # PovInput for Blum cyclide
    #
    pin = PovInput()
    pin.path = './' + get_time_str() + '_blum_cyclide/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = ( 0, -7, 0 )
    pin.cam_dct['lookat'] = ( 0, 0, 0 )
    pin.cam_dct['rotate'] = ( 20, 180, 20 )
    pin.shadow = True
    pin.light_lst = [( 0, 0, -5 ), ( 0, -5, 0 ), ( -5, 0, 0 ),
                     ( 0, 0, 5 ), ( 0, 5, 0 ), ( 5, 0, 0 ),
                     ( -5, -5, -5 ), ( 5, -5, 5 ), ( -5, -5, 5 ), ( 5, -5, -5 ) ]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2
    pin.height = 400
    pin.width = 800
    pin.quality = 11
    pin.ani_delay = 10
    pin.impl = None

    start0 = sage_QQ( 1 ) / 10  # step0=10 step1=15
    v0_lst = [ start0 + ( sage_QQ( i ) / 180 ) * sage_pi for i in range( 0, 360, 10 )]
    v1_lst = [ ( sage_QQ( i ) / 180 ) * sage_pi for i in range( 0, 360, 15 )]
    v1_lst_F = [ start0 + ( sage_QQ( i ) / 360 ) * sage_pi for i in range( 0, 720, 1 )]

    v1_lst_WE = [1.8, 2.3, 2.7, 3.1, 3.5, 3.8, 4.134, 4.31, 4.532, 4.7, 4.9, 5.08, 5.25, 5.405, 5.553, 5.7, 5.84]
    v1_lst_WF = [1.69, 1.87, 2.07, 2.26, 2.5, 2.72, 2.96, 3.2, 3.42, 3.65, 3.81]
    v1_lst_WD = [ 5.44, 5.56, 5.68, 5.81, 5.95, 6.1, 6.27, 6.474]  # [5.01, 5.12, 5.22, 5.32,

    v1_lst_SA = [6.5]; v1_lst_SE = [5.4];
    v1_lst_SB = [5.95]; v1_lst_SF = [2.28];
    v1_lst_SC = [4.83]; v1_lst_SD = [5.55];

    pin.pmz_dct['A'] = ( pmz_AB_lst, 0 )
    pin.pmz_dct['B'] = ( pmz_AB_lst, 1 )
    pin.pmz_dct['C'] = ( pmz_CB_lst, 0 )
    pin.pmz_dct['D'] = ( pmz_DB_lst, 0 )
    pin.pmz_dct['E'] = ( pmz_EB_lst, 0 )
    pin.pmz_dct['F'] = ( pmz_AF_lst, 1 )
    pin.pmz_dct['WD'] = ( pmz_DB_lst, 0 )
    pin.pmz_dct['WE'] = ( pmz_EB_lst, 0 )
    pin.pmz_dct['WF'] = ( pmz_AF_lst, 1 )
    pin.pmz_dct['SA'] = ( pmz_AB_lst, 0 )
    pin.pmz_dct['SB'] = ( pmz_AB_lst, 1 )
    pin.pmz_dct['SC'] = ( pmz_CB_lst, 0 )
    pin.pmz_dct['SD'] = ( pmz_DB_lst, 0 )
    pin.pmz_dct['SE'] = ( pmz_EB_lst, 0 )
    pin.pmz_dct['SF'] = ( pmz_AF_lst, 1 )
    pin.pmz_dct['FA'] = ( pmz_AB_lst, 0 )
    pin.pmz_dct['FB'] = ( pmz_AB_lst, 1 )
    pin.pmz_dct['FC'] = ( pmz_CB_lst, 0 )
    pin.pmz_dct['FD'] = ( pmz_DB_lst, 0 )
    pin.pmz_dct['FE'] = ( pmz_EB_lst, 0 )
    pin.pmz_dct['FF'] = ( pmz_AF_lst, 1 )

    pin.curve_dct['A'] = {'step0':v0_lst, 'step1':v1_lst, 'prec':10, 'width':0.05}
    pin.curve_dct['B'] = {'step0':v0_lst, 'step1':v1_lst, 'prec':10, 'width':0.05}
    pin.curve_dct['C'] = {'step0':v0_lst, 'step1':v1_lst, 'prec':10, 'width':0.05}
    pin.curve_dct['D'] = {'step0':v0_lst, 'step1':v1_lst, 'prec':10, 'width':0.05}
    pin.curve_dct['E'] = {'step0':v0_lst, 'step1':v1_lst, 'prec':10, 'width':0.05}
    pin.curve_dct['F'] = {'step0':v0_lst, 'step1':v1_lst, 'prec':10, 'width':0.05}

    pin.curve_dct['WD'] = {'step0':v0_lst, 'step1':v1_lst_WD, 'prec':10, 'width':0.05}
    pin.curve_dct['WE'] = {'step0':v0_lst, 'step1':v1_lst_WE, 'prec':10, 'width':0.05}
    pin.curve_dct['WF'] = {'step0':v0_lst, 'step1':v1_lst_WF, 'prec':10, 'width':0.05}

    pin.curve_dct['SA'] = {'step0':v0_lst, 'step1':v1_lst_SA, 'prec':10, 'width':0.05}
    pin.curve_dct['SB'] = {'step0':v0_lst, 'step1':v1_lst_SB, 'prec':10, 'width':0.05}
    pin.curve_dct['SC'] = {'step0':v0_lst, 'step1':v1_lst_SC, 'prec':10, 'width':0.05}
    pin.curve_dct['SD'] = {'step0':v0_lst, 'step1':v1_lst_SD, 'prec':10, 'width':0.06}
    pin.curve_dct['SE'] = {'step0':v0_lst, 'step1':v1_lst_SE, 'prec':10, 'width':0.05}
    pin.curve_dct['SF'] = {'step0':v0_lst, 'step1':v1_lst_SF, 'prec':10, 'width':0.05}

    pin.curve_dct['FA'] = {'step0':v0_lst, 'step1':v1_lst_F, 'prec':10, 'width':0.01}
    pin.curve_dct['FB'] = {'step0':v0_lst, 'step1':v1_lst_F, 'prec':10, 'width':0.01}
    pin.curve_dct['FC'] = {'step0':v0_lst, 'step1':v1_lst_F, 'prec':10, 'width':0.01}
    pin.curve_dct['FD'] = {'step0':v0_lst, 'step1':v1_lst_F, 'prec':10, 'width':0.01}
    pin.curve_dct['FE'] = {'step0':v0_lst, 'step1':v1_lst_F, 'prec':10, 'width':0.01}
    pin.curve_dct['FF'] = {'step0':v0_lst, 'step1':v1_lst_F, 'prec':10, 'width':0.01}

    col_A = rgbt2pov( ( 28, 125, 154, 0 ) )  # blue
    col_B = rgbt2pov( ( 74, 33, 0, 0 ) )  # brown
    col_C = rgbt2pov( ( 75, 102, 0, 0 ) )  # green
    col_E = col_A
    col_F = col_B
    col_D = col_C
    colFF = rgbt2pov( ( 179, 200, 217, 0 ) )  # light blue

    pin.text_dct['A'] = [True, col_A, 'phong 0.2' ]
    pin.text_dct['B'] = [True, col_B, 'phong 0.2' ]
    pin.text_dct['C'] = [True, col_C, 'phong 0.2' ]
    pin.text_dct['E'] = [True, col_E, 'phong 0.2' ]
    pin.text_dct['F'] = [True, col_F, 'phong 0.2' ]
    pin.text_dct['D'] = [True, col_D, 'phong 0.2' ]
    pin.text_dct['WE'] = [True, col_E, 'phong 0.2' ]
    pin.text_dct['WF'] = [True, col_F, 'phong 0.2' ]
    pin.text_dct['WD'] = [True, col_D, 'phong 0.2' ]
    pin.text_dct['SA'] = [True, col_A, 'phong 0.2' ]
    pin.text_dct['SB'] = [True, col_B, 'phong 0.2' ]
    pin.text_dct['SC'] = [True, col_C, 'phong 0.2' ]
    pin.text_dct['SE'] = [True, col_E, 'phong 0.2' ]
    pin.text_dct['SF'] = [True, col_F, 'phong 0.2' ]
    pin.text_dct['SD'] = [True, col_D, 'phong 0.2' ]
    pin.text_dct['FA'] = [True, colFF, 'phong 0.2' ]
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2' ]
    pin.text_dct['FC'] = [True, colFF, 'phong 0.2' ]
    pin.text_dct['FE'] = [True, colFF, 'phong 0.2' ]
    pin.text_dct['FF'] = [True, colFF, 'phong 0.2' ]
    pin.text_dct['FD'] = [True, colFF, 'phong 0.2' ]

    # raytrace image/animation
    F_lst = ['FA', 'FB', 'FC']
    S_lst = ['SA', 'SB', 'SC', 'SD', 'SE', 'SF']
    create_pov( pin, ['A', 'B', 'C'] )
    create_pov( pin, ['A', 'B', 'C'] + F_lst )
    create_pov( pin, ['WD', 'WE', 'WF'] )
    create_pov( pin, ['WD', 'WE', 'WF'] + F_lst )
    create_pov( pin, S_lst + F_lst )

    # ABC - EFD
    create_pov( pin, ['A', 'B'] + F_lst )
    create_pov( pin, ['E', 'F'] + F_lst )
Ejemplo n.º 11
0
def perseus_cyclide():
    '''
    Creates povray image of the Perseus cyclide.
    '''

    # We first construct a trigonometric parametrization
    # by rotating a circle.
    #     cos(pi/3) = 1/2
    #     sin(pi/3) = sqrt(3)/2
    #
    r, R = 1, 2
    c0, s0, c1, s1 = sage_var('c0,s0,c1,s1')
    x, y, v, w, a0 = sage_var('x,y,v,w,a0')
    q2 = sage_QQ(1) / 2
    MZ = sage_matrix([(c1, s1, 0), (-s1, c1, 0), (0, 0, 1)])
    MZc = MZ.subs({c1: q2, s1: q2 * a0})
    V = sage_vector([r * c0, 0, r * s0])
    V = MZc * V
    V[0] = V[0] + R
    pmz_AB_lst = list(MZ * V)

    OrbTools.p('V =', V)
    OrbTools.p('pmz_AB_lst =', pmz_AB_lst)
    for pmz in pmz_AB_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # We convert the trigonometric parametrization to a
    # rational parametrization, via the following formulas:
    #
    #     cos(s) = (y^2-x^2) / (y^2+x^2)
    #     sin(s) = 2*x*y / (y^2+x^2)
    #     y=1; x = arctan( s/2 )
    #
    C0 = (y**2 - x**2) / (y**2 + x**2)
    S0 = 2 * x * y / (y**2 + x**2)
    C1 = (w**2 - v**2) / (w**2 + v**2)
    S1 = 2 * v * w / (w**2 + v**2)
    den = (y**2 + x**2) * (w**2 + v**2)
    dct = {c0: C0, s0: S0, c1: C1, s1: S1}
    pmz_lst = [den] + [(elt.subs(dct) * den).simplify_full()
                       for elt in list(MZ * V)]
    OrbTools.p('pmz_lst =', pmz_lst)
    for pmz in pmz_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # do a basepoint analysis on the rational parametrization
    #
    ring = PolyRing('x,y,v,w', True).ext_num_field('t^2-3')
    ls = LinearSeries([str(pmz) for pmz in pmz_lst], ring)
    OrbTools.p(ls.get_bp_tree())

    # construct linear series for families of conics
    #
    ring = PolyRing(
        'x,y,v,w')  # construct polynomial ring over new ground field
    OrbTools.p(ring)
    x, y, v, w = ring.gens()
    a0, a1, a2, a3 = ring.root_gens()

    p1 = ['xv', (-a3, a1)]
    p2 = ['xv', (-a2, -a1)]
    p3 = ['xv', (a3, a1)]
    p4 = ['xv', (a2, -a1)]

    bpt_1234 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_1234.add(p1[0], p1[1], 1)
    bpt_1234.add(p2[0], p2[1], 1)
    bpt_1234.add(p3[0], p3[1], 1)
    bpt_1234.add(p4[0], p4[1], 1)

    bpt_12 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_12.add(p1[0], p1[1], 1)
    bpt_12.add(p2[0], p2[1], 1)

    bpt_34 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_34.add(p3[0], p3[1], 1)
    bpt_34.add(p4[0], p4[1], 1)

    ls_22 = LinearSeries.get([2, 2], bpt_1234)
    ls_21 = LinearSeries.get([2, 1], bpt_1234)
    ls_12 = LinearSeries.get([1, 2], bpt_1234)
    ls_11a = LinearSeries.get([1, 1], bpt_12)
    ls_11b = LinearSeries.get([1, 1], bpt_34)

    OrbTools.p('linear series 22 =\n', ls_22)
    OrbTools.p('linear series 21 =\n', ls_21)
    OrbTools.p('linear series 12 =\n', ls_12)
    OrbTools.p('linear series 11a =\n', ls_11a)
    OrbTools.p('linear series 11b =\n', ls_11b)

    # compute reparametrization from the linear series of families
    ring = PolyRing('x,y,v,w,c0,s0,c1,s1')
    OrbTools.p(ring)
    x, y, v, w, c0, s0, c1, s1 = ring.gens()
    a0, a1, a2, a3 = ring.root_gens()
    pmz_AB_lst = [1] + ring.coerce(pmz_AB_lst)
    pmz_lst = ring.coerce(pmz_lst)

    q2 = sage_QQ(1) / 2
    a = 2 * a0 / 3
    b = (-a0 * a1 / 3 - q2) * a3
    c = (a0 * a1 / 3 - q2) * a2
    d = (a1 / 2 - a0 / 3) * a3
    e = (-a1 / 2 - a0 / 3) * a2
    bc = b + c
    de = d + e

    X = 1 - s0
    Y = c0
    V = 1 - s1
    W = c1
    CB_dct = {
        x: X,
        y: Y,
        v: W * X + bc * W * Y - de * V * Y,
        w: V * X + bc * V * Y + de * W * Y
    }
    DB_dct = {
        x: X,
        y: Y,
        v: W * X - bc * W * Y + de * V * Y,
        w: V * X - bc * V * Y - de * W * Y
    }
    EB_dct = {
        x: X,
        y: Y,
        v: W * X**2 + W * Y**2 - a * V * Y**2,
        w: V * X**2 + V * Y**2 + a * W * Y**2
    }
    pmz_CB_lst = [pmz.subs(CB_dct) for pmz in pmz_lst]  # CB  11a
    pmz_DB_lst = [pmz.subs(DB_dct) for pmz in pmz_lst]  # CB  11b
    pmz_EB_lst = [pmz.subs(EB_dct) for pmz in pmz_lst]  # CB  21

    # output
    OrbTools.p('pmz_AB_lst =\n', pmz_AB_lst)
    OrbTools.p('pmz_CB_lst =\n', pmz_CB_lst)
    OrbTools.p('pmz_DB_lst =\n', pmz_DB_lst)
    OrbTools.p('pmz_EB_lst =\n', pmz_EB_lst)

    # approximate by map defined over rational numbers
    ci_idx = 5  # index defining the complex embedding
    pmz_AB_lst = OrbRing.approx_QQ_pol_lst(pmz_AB_lst, ci_idx)
    pmz_CB_lst = OrbRing.approx_QQ_pol_lst(pmz_CB_lst, ci_idx)
    pmz_DB_lst = OrbRing.approx_QQ_pol_lst(pmz_DB_lst, ci_idx)
    pmz_EB_lst = OrbRing.approx_QQ_pol_lst(pmz_EB_lst, ci_idx)

    # mathematica input
    ms = ''
    for pmz, AB in [(pmz_lst, 'ZZ'), (pmz_AB_lst, 'AB'), (pmz_CB_lst, 'CB'),
                    (pmz_DB_lst, 'DB'), (pmz_EB_lst, 'EB')]:
        s = 'pmz' + AB + '=' + str(pmz) + ';'
        s = s.replace('[', '{').replace(']', '}')
        ms += '\n' + s
    OrbTools.p('Mathematica input =', ms)

    # PovInput ring cyclide
    #
    pin = PovInput()

    pin.path = './' + get_time_str() + '_perseus_cyclide/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, 7, 0)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (45, 0, 0)
    pin.shadow = True
    pin.light_lst = [(0, 0, -10), (0, -10, 0), (-10, 0, 0), (0, 0, 10),
                     (0, 10, 0), (10, 0, 0)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2
    pin.height = 400
    pin.width = 800
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_AB_lst, 0)
    pin.pmz_dct['B'] = (pmz_AB_lst, 1)
    pin.pmz_dct['C'] = (pmz_CB_lst, 0)
    pin.pmz_dct['D'] = (pmz_DB_lst, 0)
    pin.pmz_dct['E'] = (pmz_EB_lst, 0)

    pin.pmz_dct['FA'] = (pmz_AB_lst, 0)
    pin.pmz_dct['FB'] = (pmz_AB_lst, 1)
    pin.pmz_dct['FC'] = (pmz_CB_lst, 0)
    pin.pmz_dct['FD'] = (pmz_DB_lst, 0)
    pin.pmz_dct['FE'] = (pmz_EB_lst, 0)

    v0_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]
    v1_lst_A = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]  # 5
    v1_lst_B = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 15)]
    v1_lst_C = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 36)]
    v1_lst_D = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 36)]
    v1_lst_E = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]  # 5

    v1_lst_F = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 1)]

    prec = 50

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_lst_A,
        'prec': prec,
        'width': 0.04
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_lst_B,
        'prec': prec,
        'width': 0.04
    }
    pin.curve_dct['C'] = {
        'step0': v0_lst,
        'step1': v1_lst_C,
        'prec': prec,
        'width': 0.05
    }
    pin.curve_dct['D'] = {
        'step0': v0_lst,
        'step1': v1_lst_D,
        'prec': prec,
        'width': 0.05
    }
    pin.curve_dct['E'] = {
        'step0': v0_lst,
        'step1': v1_lst_E,
        'prec': prec,
        'width': 0.04
    }

    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['FC'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['FD'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['FE'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.01
    }

    col_A = (0.6, 0.0, 0.0, 0.0)  # red
    col_B = (0.8, 0.6, 0.2, 0.0)  # beige
    col_C = (0.6, 0.0, 0.0, 0.0
             )  # red   *** rgbt2pov( ( 74, 33, 0, 0 ) )     # brown
    col_D = (0.2, 0.6, 0.0, 0.0
             )  # green *** rgbt2pov( ( 28, 125, 154, 0 ) )  # blue
    col_E = (0.2, 0.6, 0.0, 0.0)  # green
    colFF = (0.1, 0.1, 0.1, 0.0)

    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['C'] = [True, col_C, 'phong 0.2 phong_size 5']
    pin.text_dct['D'] = [True, col_D, 'phong 0.2 phong_size 5']
    pin.text_dct['E'] = [True, col_E, 'phong 0.2 phong_size 5']

    pin.text_dct['FA'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FC'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FD'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FE'] = [True, colFF, 'phong 0.2 phong_size 5']

    # raytrace image/animation
    create_pov(pin, ['C', 'D', 'FC', 'FD'])
    create_pov(pin, ['A', 'B', 'FC', 'FD'])
    create_pov(pin, ['E', 'B', 'FC', 'FD'])
Ejemplo n.º 12
0
def usecase_celestial_types():
    '''
    Let surface X in P^m be the blowups of P^1xP^1 in either 0 or 2 complex conjugate  
    points so that m=8 and m=6 respectively. 
    Here P^1xP^1 denotes the fiber product of the projective line with itself. 
    We verify for n in [3,4,5,6,7] whether X can be linearly projected into the 
    projective n-sphere S^n.  
    
    If m=8, then the celestial type is (2,8,n), where the first entry denotes 
    the number of conics contained in X through (almost) every point.
    
    If m=6, then the celestial type is (3,6,n) or (2,6,n). If X in S^5 has celestial type
    (2,6,5), then X has a real isolated singularity (see dp6_sing() for a visualization)).  
    '''

    # We provide certificates "c_lst" and "prv_Q" for "get_surf()",
    # which were obtained by a previous (long) computation.

    #
    # P^1xP^1
    #
    # We construct a parametrization of the double Segre surface dP8 in
    # projective 8-space. This surface contains 2 conics through each point
    #
    ring = PolyRing('x,y,v,w', True)
    ls_dP8 = LinearSeries(get_mon_lst([2, 2], ring.gens()), ring)
    OrbTools.p('ls_dP8 =', ls_dP8)

    get_surf(ls_dP8, (7 + 1, 1), [
        -8, -8, -10, -6, -7, 6, 5, 6, 0, -8, -2, -7, -7, 7, -1, 0, -9, 7, 1, -9
    ])

    prv_Q = sage_matrix([(0, 0, 0, 1, 1, 1, 0, 0, 0),
                         (0, 1, 0, 0, 0, 0, 0, 0, 0),
                         (1, 0, 1, 1, 0, 0, 0, 1, 0),
                         (1, 0, 0, 1, 0, 0, 1, 0, 0),
                         (0, 0, 0, 0, 0, 0, 1, 0, 1),
                         (0, 1, 0, 0, 1, 0, 1, 0, 1),
                         (0, 0, 0, 1, 1, 0, 1, 0, 1),
                         (1, 0, 0, 1, 0, 0, 1, 1, 0)])
    get_surf(
        ls_dP8, (6 + 1, 1),
        [3, -3, 3, -7, 7, 1, -4, 3, -10, 6, -4, -6, -6, 4, -9, 3, -6, -4, 1],
        prv_Q)

    prv_Q = sage_matrix([(0, 1, 0, 0, 1, 0, 1, 0, 1),
                         (1, 1, 1, 1, 0, 1, 0, 0, 1),
                         (1, 1, 0, 1, 1, 1, 1, 0, 1),
                         (1, 1, 1, 1, 1, 1, 1, 1, 1),
                         (1, 0, 1, 0, 1, 0, 1, 0, 0),
                         (0, 0, 1, 0, 1, 0, 0, 1, 0),
                         (0, 0, 0, 0, 0, 0, 1, 1, 1)])
    get_surf(ls_dP8, (5 + 1, 1), [
        -7, -2, -1, -5, -4, 6, -2, -2, -2, 2, 9, -4, -9, -4, 2, -10, 9, -6, -1
    ], prv_Q)

    prv_Q = sage_matrix([(0, 1, 0, 1, 1, 1, 0, 1, 1),
                         (1, 0, 0, 0, 1, 1, 0, 1, 1),
                         (1, 0, 0, 0, 1, 0, 0, 0, 1),
                         (0, 1, 1, 0, 0, 0, 1, 1, 0),
                         (1, 1, 1, 0, 0, 0, 1, 1, 0),
                         (0, 1, 1, 1, 0, 1, 1, 1, 0)])
    get_surf(ls_dP8, (4 + 1, 1),
             [-2, -3, 6, 7, -10, -2, -4, -8, -3, -4, 4, -6], prv_Q)

    #
    # P^1xP^1 blown up in two general complex conjugate points
    #
    # We construct a parametrization of a sextic del Pezzo surface dP6
    # in projective 6-space, that contains 3 conics through each point.
    # We show that dP6 can be projected into S^5 and S^4.
    #
    a0 = PolyRing('x,y,v,w', True).ext_num_field('t^2 + 1').root_gens()[0]
    bp_tree = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bp_tree.add('xv', (-a0, a0), 1)
    bp_tree.add('xv', (a0, -a0), 1)
    ls_dP6 = LinearSeries.get([2, 2], bp_tree)
    OrbTools.p('ls_dP6 =', ls_dP6)
    get_surf(ls_dP6, (5 + 1, 1), [-9, -6, 1, 4, -1, -8, -5, -5, -4, 8, 1])
    prv_Q = sage_matrix([(0, 0, 0, 1, 0, 1, 1), (1, 1, 0, 1, 0, 0, 0),
                         (0, 1, 1, 0, 1, 0, 1), (1, 1, 0, 0, 1, 0, 0),
                         (1, 1, 1, 1, 1, 1, 0), (1, 0, 0, 1, 0, 1, 1)])
    get_surf(ls_dP6, (4 + 1, 1), [-1, -9, -10, -7, -10, -8, 0], prv_Q)

    #
    # P^1xP^1 blown up in two complex conjugate points that lie in the same fiber
    #
    # We construct a parametrization of a sextic weak del Pezzo surface wdP6
    # in projective 6-space, that contains 2 conics through each point.
    # We show that wdP6 can be projected into S^5 and S^4.
    #
    a0 = PolyRing('x,y,v,w', True).ext_num_field('t^2 + 1').root_gens()[0]
    bp_tree = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bp_tree.add('xv', (a0, 0),
                1)  # the complex conjugate base points lie in the same fiber
    bp_tree.add('xv', (-a0, 0), 1)
    ls_wdP6 = LinearSeries.get([2, 2], bp_tree)
    OrbTools.p('ls_wdP6 =', ls_wdP6)
    get_surf(ls_wdP6, (5 + 1, 1), [-6, 8, -7, -8, 0, -8, 2, -5, -8])
    prv_Q = sage_matrix([(1, 0, 0, 1, 1, 1, 0), (1, 0, 0, 1, 0, 1, 1),
                         (0, 1, 1, 1, 0, 1, 0), (0, 0, 0, 0, 1, 0, 0),
                         (0, 1, 0, 1, 1, 1, 0), (0, 0, 0, 1, 1, 1, 0)])
    get_surf(ls_wdP6, (4 + 1, 1), [-2, -7, -6, -10, -2, -4, 4], prv_Q)
Ejemplo n.º 13
0
def quadric_smooth():
    '''
    Construct povray image of rulings on hyperboloid of one sheet.
    '''

    # construct the two rulings on the hyperboloid
    # by rotating lines L1 and L2
    c0, s0, c1, s1, t0 = OrbRing.coerce('c0,s0,c1,s1,t0')
    P = sage_vector([-2, -1, -0.5])
    Q = sage_vector([2, -1, -0.5])
    L0 = t0 * P + (t0 - 1) * Q
    L1 = t0 * Q + (t0 - 1) * P
    M = sage_matrix([(c1, s1, 0), (-s1, c1, 0), (0, 0, 1)])
    pmz_A_lst = [1] + list(M * L0)
    pmz_B_lst = [1] + list(M * L1)

    OrbTools.p('pmz_A_lst =', pmz_A_lst)
    for pmz in pmz_A_lst:
        OrbTools.p('\t\t', pmz)

    OrbTools.p('pmz_B_lst =', pmz_B_lst)
    for pmz in pmz_B_lst:
        OrbTools.p('\t\t', pmz)

    # PovInput ring cyclide
    #
    pin = PovInput()

    pin.path = './' + get_time_str() + '_quadric_smooth/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, -10, 0)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (0, 0, 0)
    pin.shadow = True
    pin.light_lst = [(0, 0, -5), (0, -5, 0), (-5, 0, 0), (0, 0, 5), (0, 5, 0),
                     (5, 0, 0)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2

    pin.width = 400
    pin.height = 800
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_A_lst, 0)
    pin.pmz_dct['B'] = (pmz_B_lst, 0)
    pin.pmz_dct['FA'] = (pmz_A_lst, 0)
    pin.pmz_dct['FB'] = (pmz_B_lst, 0)

    v0_lst = [sage_QQ(i) / 10 for i in range(-15, 30, 5)]  # -15, 35
    v1_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 36)]
    v1_lst_F = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 2)]

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_lst,
        'prec': 10,
        'width': 0.1
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_lst,
        'prec': 10,
        'width': 0.1
    }
    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': 10,
        'width': 0.01
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': 10,
        'width': 0.01
    }

    col_A = (0.5, 0.0, 0.0, 0.0)  # red
    col_B = rgbt2pov((28, 125, 154, 0))  # blue

    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['FA'] = [True, (0.1, 0.1, 0.1, 0.0), 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, (0.1, 0.1, 0.1, 0.0), 'phong 0.2 phong_size 5']

    # raytrace image/animation
    create_pov(pin, ['A', 'B', 'FA', 'FB'])
Ejemplo n.º 14
0
def get_sing_lst( pol, probable = True ):
    '''
    The method requires that the magma-command 
    is in "os.environ['PATH']".    
    See [http://magma.maths.usyd.edu.au/magma/].
    
    Parameters
    ----------
    pol : OrbRing.R       
        A homogeneous polynomial in QQ[x0,x1,x2,x3].
        
    probable : boolean
        If True, performs a non-deterministic version of a 
        radical decomposition algorithm, which is faster.
        The correctness of output is not guaranteed in this case.
    
    Returns
    -------
    list
        Suppose that X is the surface defined by the zero-set of "pol".
        The output is a list           
            [ (<I>, <H>), ... ]          
        where <I> is the ideal of a component in singular locus of X, 
        and <H> is the Hilbert polynomial of this ideal.
        If Magma is not accessible, then the empty-list [] is returned.
        
    '''
    x0, x1, x2, x3 = OrbRing.coerce( 'x0,x1,x2,x3' )
    df_str = str( [sage_diff( pol, x0 ), sage_diff( pol, x1 ), sage_diff( pol, x2 ), sage_diff( pol, x3 )] )[1:-1]

    OrbTools.p( df_str )

    mi = ''
    mi += 'P<x0,x1,x2,x3> := PolynomialRing(RationalField(), 4);\n'
    mi += 'MI := ideal< P |' + df_str + '>;\n'

    if probable:
        mi += 'MD := ProbableRadicalDecomposition( MI );\n'
    else:
        mi += 'MD := RadicalDecomposition( MI );\n'
    mi += '#MD;\n'

    try:
        mo1 = int( sage_magma.eval( mi ) )
    except:
        return []

    sing_lst = []
    Ry = sage_PolynomialRing( OrbRing.num_field, sage_var( 'y0,y1,y2,y3' ), order = 'degrevlex' )
    for idx in range( mo1 ):

        comp = str( sage_magma.eval( 'Basis(MD[' + str( idx + 1 ) + ']);\n' ) )
        comp = comp.replace( '\n', '' )

        # compute hilbert polynomial of component in singular locus
        compy = sage__eval( comp.replace( 'x', 'y' ), Ry.gens_dict() )
        idy = Ry.ideal( compy )
        hpol = idy.hilbert_polynomial()

        sing_lst += [( comp, hpol )]
        OrbTools.p( idx, sing_lst[-1] )

    OrbTools.p( sing_lst )

    return sing_lst
Ejemplo n.º 15
0
def usecase__two_sphere_cyclide():
    '''
    Construct parametrization of families of circles
    on the sphere cyclide. The sphere cyclide is 
    a quartic del Pezzo surface embedded into
    projective 3-sphere. This surface has two families
    of circles, but is not rational. 
    '''

    R = sage_PolynomialRing(sage_QQ, 'a')
    a = R.gens()[0]
    B = sage_NumberField([a**2 - 1 / sage_QQ(2)], 'a0')
    B = sage_FractionField(sage_PolynomialRing(B, 'k'))
    OrbTools.p(ring_dict(B))

    S = '[-y0^2+y1^2+y2^2+y3^2+y4^2]'
    X = '[(x1^2+x2^2+x3^2)^2-x0^2*(8*x1^2-2*x2^2-2*x3^2-2*x0^2)]'
    OrbTools.p(euclidean_type_form(X[1:-1]))

    p = '[y0-y4,y1,y2,y3]'
    m = '[y4,y1+a0*y0]'
    P = '[x0-k*x1]'

    f = invert_birational_map(p, S)
    OrbTools.p('f =', f)

    Y = image_map(f, X)
    OrbTools.p('Y =', len(Y), Y)
    OrbTools.p('Y =', hilbert_poly(Y))

    F = preimage_map(m, Y, P, B)
    OrbTools.p('F =', len(F), F)

    C = image_map(p, F, B)
    OrbTools.p('C =', len(C), C)

    for i in range(len(C)):
        s = str(C[i])
        for (a, b) in [('a0', 'sqrt(1/2)'), ('k', 'p1'), ('x0', '1'),
                       ('x1', 'x'), ('x2', 'y'), ('x3', 'z')]:
            s = s.replace(a, b)
        print(s)
Ejemplo n.º 16
0
def get_project( pol_lst, pmat ):
    '''
    Parameters
    ----------
    pol_lst : list<OrbRing.R> 
        A list of homogeneous polynomials in QQ[x0,...,x8].
    
    pmat : sage_matrix    
        A matrix defined over the rationals QQ.    
    
    Returns
    -------
    tuple
        A 2-tuple of polynomials:        
        * a homogeneous polynomial F in QQ[x0,x1,x2,x3].             
        * F(1,x,y,z) in QQ[x,y,z] (affine polynomial)
    '''

    Ry = sage_PolynomialRing( sage_GF( 2 ), sage_var( 'y0,y1,y2,y3,y4,y5,y6,y7,y8' ), order = 'degrevlex' )
    v = OrbRing.coerce( '[v0,v1,v2,v3,v4,v5,v6,v7,v8]' )
    x = OrbRing.coerce( '[x0,x1,x2,x3,x4,x5,x6,x7,x8]' )
    vx_dct = {v[i]:x[i] for i in range( 9 )}

    OrbTools.p( "\n" + str( pmat ) )

    tries = 0
    projected = False
    while not projected:

        # obtain the linear equations of the projection map
        pmat = sage_matrix( OrbRing.R, list( pmat ) )
        leq_lst = list( pmat * sage_vector( x ) )

        # compute the image of this projection map
        proj_lst = [ v[i] - leq_lst[i] for i in range( len( leq_lst ) ) ]
        p_lst = sage_ideal( pol_lst + proj_lst ).elimination_ideal( x ).gens()

        # obtain a polynomial in x0,...,x8
        p_lst = [p.subs( vx_dct ) for p in p_lst]
        fx = p_lst[0]

        tries += 1
        if len( fx.variables() ) < 4 or len( p_lst ) != 1:

            pmat = get_pmat( True )

            if tries % 100 == 0:
                OrbTools.p( 'tries =', tries, p_lst )

            if tries == 1000:
                return -1
        else:
            projected = True

    w0, w1, w2, w3 = fx.variables()
    fx = fx.subs( {w0:x[0], w1:x[1], w2:x[2], w3:x[3]} )

    x0, x1, x2, x3 = OrbRing.coerce( 'x0,x1,x2,x3' )
    x, y, z = sage_var( 'x,y,z' )
    fxyz = fx.subs( {x0:1, x1:x, x2:y, x3:z} )

    OrbTools.p( fx )
    OrbTools.p( fxyz )

    return fx, fxyz
Ejemplo n.º 17
0
    def test__tool_dct(self):

        orb = OrbTools()
        orb2 = OrbTools()

        # watch out to not use the default file name
        # otherwise it might take long to load the data
        test_fname = 'test_tools'
        key = 'test__tool_dct'

        dct = orb.get_tool_dct(fname=test_fname)
        dct[key] = True
        orb.save_tool_dct(fname=test_fname)

        assert key in orb.get_tool_dct(fname=test_fname)
        assert key in orb2.get_tool_dct(fname=test_fname)

        orb.set_enable_tool_dct(False)
        assert key not in orb.get_tool_dct(fname=test_fname)
        assert key not in orb2.get_tool_dct(fname=test_fname)

        orb.set_enable_tool_dct(True)
        assert key in orb.get_tool_dct(fname=test_fname)
        assert key in orb2.get_tool_dct(fname=test_fname)
Ejemplo n.º 18
0
def veronese():
    '''
    Construct povray image of a 3-web of conics on the Veronese surface.
    '''

    #############################################
    # Construct projection of Veronese surface. #
    #############################################

    c0, s0, c1, s1, t0 = sage_var('c0,s0,c1,s1,t0')
    x, y = sage_var('x,y')

    pmz_A_lst = [1, c0 * s0 * s1, c0 * s0 * c1, c0 * c0 * c1 * s1]

    P1 = c0 / (s0 - 1)
    P2 = c1 / (s1 - 1)
    P3 = (s0 / c0) * (c1 / (s1 - 1))

    dct_CD = {x: P1, y: P2}
    den_CD = (s0 - 1)**2 * (s1 - 1)**2

    dct_ED = {x: P3, y: P2}
    den_ED = c0**2 * (s1 - 1)**2

    pmz_lst = [x**2 + y**2 + 1, -x, -x * y, y]
    pmz_B_lst = [(pmz.subs(dct_CD) * den_CD).expand() for pmz in pmz_lst]
    pmz_C_lst = [(pmz.subs(dct_ED) * den_ED).expand() for pmz in pmz_lst]

    # parametrization of circles
    #
    pmz_C1_lst = [pmz.subs({x: t0, y: -t0 - 1}) for pmz in pmz_lst]
    pmz_C2_lst = [pmz.subs({x: t0, y: -t0 + 1}) for pmz in pmz_lst]
    pmz_C3_lst = [pmz.subs({x: t0, y: t0 + 1}) for pmz in pmz_lst]
    pmz_C4_lst = [pmz.subs({x: t0, y: t0 - 1}) for pmz in pmz_lst]

    # output
    #
    lst_lst = [('A', pmz_A_lst), ('B', pmz_B_lst), ('C', pmz_C_lst)]
    lst_lst += [
        ('C1', pmz_C1_lst),
        ('C2', pmz_C2_lst),
        ('C3', pmz_C3_lst),
        ('C4', pmz_C4_lst),
    ]
    for A, pmz_lst in lst_lst:
        OrbTools.p('pmz_' + A + '_lst =', pmz_lst)
        for pmz in pmz_lst:
            OrbTools.p('\t\t', sage_factor(pmz))

    #############################
    # PovInput Veronese surface #
    #############################

    pin = PovInput()

    pin.path = './' + get_time_str() + '_veronese/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, -1.2, 0)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (35, 0, 45)
    pin.shadow = True
    pin.light_lst = [(0, 0, -5), (0, -5, 0), (-5, 0, 0), (0, 0, 5), (0, 5, 0),
                     (5, 0, 0)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 0.5
    pin.height = 400
    pin.width = 800
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_A_lst, 0)
    pin.pmz_dct['B'] = (pmz_B_lst, 1)
    pin.pmz_dct['C'] = (pmz_C_lst, 1)

    pin.pmz_dct['FA'] = (pmz_A_lst, 0)
    pin.pmz_dct['FB'] = (pmz_B_lst, 1)
    pin.pmz_dct['FC'] = (pmz_C_lst, 1)

    pin.pmz_dct['FA2'] = (pmz_A_lst, 0)
    pin.pmz_dct['FB2'] = (pmz_B_lst, 1)
    pin.pmz_dct['FC2'] = (pmz_C_lst, 1)

    pin.pmz_dct['C1'] = (pmz_C1_lst, 0)
    pin.pmz_dct['C2'] = (pmz_C2_lst, 0)
    pin.pmz_dct['C3'] = (pmz_C3_lst, 0)
    pin.pmz_dct['C4'] = (pmz_C4_lst, 0)

    v0_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 5)]
    v1_A_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 9)]
    v1_B_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 18)]
    v1_C_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 9)]

    v1_lst_F = [(sage_QQ(i) / (3 * 180)) * sage_pi
                for i in range(0, 3 * 360, 1)]
    v1_lst_F2 = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 2)]

    v0_lst_CC = [sage_QQ(i) / 10 for i in range(-100, 100, 1)]

    prec = 50

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_A_lst,
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_B_lst,
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['C'] = {
        'step0': v0_lst,
        'step1': v1_C_lst,
        'prec': prec,
        'width': 0.01
    }

    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.001
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.001
    }
    pin.curve_dct['FC'] = {
        'step0': v0_lst,
        'step1': v1_lst_F,
        'prec': prec,
        'width': 0.001
    }

    pin.curve_dct['FA2'] = {
        'step0': v0_lst,
        'step1': v1_lst_F2,
        'prec': prec,
        'width': 0.001
    }
    pin.curve_dct['FB2'] = {
        'step0': v0_lst,
        'step1': v1_lst_F2,
        'prec': prec,
        'width': 0.001
    }
    pin.curve_dct['FC2'] = {
        'step0': v0_lst,
        'step1': v1_lst_F2,
        'prec': prec,
        'width': 0.001
    }

    pin.curve_dct['C1'] = {
        'step0': v0_lst_CC,
        'step1': [0],
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['C2'] = {
        'step0': v0_lst_CC,
        'step1': [0],
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['C3'] = {
        'step0': v0_lst_CC,
        'step1': [0],
        'prec': prec,
        'width': 0.01
    }
    pin.curve_dct['C4'] = {
        'step0': v0_lst_CC,
        'step1': [0],
        'prec': prec,
        'width': 0.01
    }

    col_A = (0.6, 0.4, 0.1, 0.0)
    col_B = (0.1, 0.15, 0.0, 0.0)
    col_C = (0.2, 0.3, 0.2, 0.0)
    colFF = (0.1, 0.1, 0.1, 0.0)
    colCC = (0.6, 0.0, 0.0, 0.0)

    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['C'] = [True, col_C, 'phong 0.2 phong_size 5']

    pin.text_dct['FA'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FC'] = [True, colFF, 'phong 0.2 phong_size 5']

    pin.text_dct['FA2'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB2'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FC2'] = [True, colFF, 'phong 0.2 phong_size 5']

    pin.text_dct['C1'] = [True, colCC, 'phong 0.2 phong_size 5']
    pin.text_dct['C2'] = [True, colCC, 'phong 0.2 phong_size 5']
    pin.text_dct['C3'] = [True, colCC, 'phong 0.2 phong_size 5']
    pin.text_dct['C4'] = [True, colCC, 'phong 0.2 phong_size 5']

    ############################
    # raytrace image/animation #
    ############################

    # four circles on projection Veronese surface
    pin.cam_dct['location'] = (0, -1.5, 0)
    pin.cam_dct['rotate'] = (60, 10, 45)
    create_pov(pin, ['FA2', 'FB2', 'FC2'])
    create_pov(pin, ['C1', 'C2', 'C3', 'C4'] + ['FA2', 'FB2', 'FC2'])

    # hexagonal web on Veronese surface
    pin.cam_dct['location'] = (0, -1.2, 0)
    pin.cam_dct['rotate'] = (35, 0, 45)
    create_pov(pin, ['A', 'B', 'C'])
    create_pov(pin, ['A', 'B', 'C', 'FA', 'FB', 'FC'])
    create_pov(pin, ['FA2', 'FB2', 'FC2'])
Ejemplo n.º 19
0
def dp8_clifford():
    '''    
    Construct povray image of octic del Pezzo surface in S^3.
    The surface is created as the Clifford translation of a
    great circle along a little circle.        
    '''

    # construct surface as pointwise hamiltonian product of
    # two circles in S^3
    #
    T = get_trn_S3([0, 0, 0])
    R = get_rot_S3(6 * [0])
    S = get_scale_S3(1)
    A = S * R * T

    q32 = sage_QQ(3) / 2
    T = get_trn_S3([q32, 0, 0])
    R = get_rot_S3(6 * [0])
    S = get_scale_S3(1)
    B = S * R * T

    c0, s0, c1, s1 = OrbRing.coerce('c0,s0,c1,s1')
    u = list(A * sage_vector([1, c0, s0, 0, 0]))
    v = list(B * sage_vector([1, c1, s1, 0, 0]))
    p = get_hp_P4(u, v)
    pmz_AB_lst = [p[0] - p[4], p[1], p[2], p[3]]

    for pmz in pmz_AB_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # PovInput dp8 clifford
    #
    pin = PovInput()

    pin.path = './' + get_time_str() + '_dp8_clifford/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, 0, 4)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (0, 0, 0)
    pin.shadow = True
    pin.light_lst = [(0, 0, -10), (0, -10, 0), (-10, 0, 0), (0, 0, 10),
                     (0, 10, 0), (10, 0, 0)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2
    pin.height = 400
    pin.width = 800
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_AB_lst, 0)
    pin.pmz_dct['B'] = (pmz_AB_lst, 1)

    pin.pmz_dct['FA'] = (pmz_AB_lst, 0)
    pin.pmz_dct['FB'] = (pmz_AB_lst, 1)

    v0_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 5)]
    v1_lst_A = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 10)]
    v1_lst_A += [(sage_QQ(i) / 180) * sage_pi for i in range(180, 360, 20)]
    v1_lst_B = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]

    v1_lst_FA = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 1)]
    v1_lst_FA += [(sage_QQ(i) / 180) * sage_pi for i in range(180, 360, 2)]
    v1_lst_FB = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 1)]

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_lst_A,
        'prec': 10,
        'width': 0.04
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_lst_B,
        'prec': 10,
        'width': 0.04
    }
    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lst_FA,
        'prec': 10,
        'width': 0.02
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lst_FB,
        'prec': 10,
        'width': 0.02
    }

    col_A = (0.6, 0.4, 0.1, 0.0)
    col_B = (0.1, 0.15, 0.0, 0.0)
    colFF = (0.1, 0.1, 0.1, 0.0)
    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['FA'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2 phong_size 5']

    # raytrace image/animation
    create_pov(pin, ['A', 'B'])
    create_pov(pin, ['A', 'B', 'FA', 'FB'])
    create_pov(pin, ['A', 'FA', 'FB'])
    create_pov(pin, ['B', 'FA', 'FB'])
Ejemplo n.º 20
0
def pov_ani(pin, fam, show_surf=False, ft_lst=[]):
    '''
    Parameters
    ----------
    pin : PovInput       
        The following attributes of the PovInput object are used:    
        * "pin.path"
        * "pin.fname"
        * "pin.ani_delay"
                                                
    fam : string 
        A string key for the family which should be animated. 
                 
    show_surf : bool
        If True then the surface on which the family lives is rendered.
                         
    ft_lst : list<(string,float)>   
        A list of pairs: [(<fam>,<t>)]
        where <fam> is a string denoting a family id
        and <t> is a float in [0,1] representing transparancy.
    
    Returns
    -------        
        An animated gif at "pin.path". 
        In each frame, all curves in family <fam> are 
        rendered with transparancy <t>, for all (<fam>,<t>) in "ft_lst", 
        such that <fam> is *not* the family that is animated.  
    '''
    # total number of curves that are raytraced in the
    # animation.
    num_curves = 0

    # Raytrace the families and store into indexed ".png"
    # files.
    #
    path = pin.path
    fname = pin.fname
    nc = len(get_curve_lst(pin, fam))
    nc += 5  # delays loops between animations
    for idx in range(0, nc):

        OrbTools.p('idx =', idx, '/', nc)

        # set texture transparency in preamble
        col_dct = {}
        for f, t in ft_lst:
            if f != fam:
                col_dct[f] = pin.text_dct[f][1]
                pin.text_dct[f][1] = tuple(list(col_dct[f][:-1]) + [t])
        pov_str = create_pov_preamble(pin)
        for f, t in ft_lst:
            if f != fam:
                pin.text_dct[f][1] = col_dct[f]  # reset to previous value

        # setup implicit surface
        if show_surf:
            pov_str += create_pov_surface(pin)

        # setup curves in animated family
        pov_str += create_pov_curves(pin, fam, idx)

        # setup families in ft_lst
        for f, t in ft_lst:
            if f != fam:
                pov_str += create_pov_curves(pin, f)

        # start raytracing
        pin.fname = fname + '-' + str(idx)
        pin.path = path + 'ani/'
        pov_raytrace(pin, pov_str)

    pin.path = path
    pin.fname = fname

    # create animated gif
    convert_pngs_gif(pin.path, pin.fname, nc, pin.ani_delay)
Ejemplo n.º 21
0
        # prj_pol{x0:0} = (25) * (x1^2 + x2^2 + x3^2)^2
        # xyz_pol       = 25*x^4 + 50*x^2*y^2 + 25*y^4 + 50*x^2*z^2 + 50*y^2*z^2 + 25*z^4 - 100*x^3 - 100*x*y^2 + 20*x^2*z + 20*y^2*z - 100*x*z^2 + 20*z^3 + 50*x^2 - 50*y^2 - 40*x*z - 41*z^2 + 100*x - 24*z + 25
        # pmz_test      = True
        # fct_lst       = 1 factors
        # sng_lst       = 1 components
        #               ~ ('[x0,x1^2 + x2^2 + x3^2]', 2*t + 1)
        # short_str     =
        #     s="['@(4,3)=(deg,emb)', {'pmat': ('P0', 'I', 'I'), 'omat': ('T[1, 0, 0, 0, 0, 0, 0]', 'Orppp', 'T[-1, 0, 0, 0, 0, 0, 0]'), 'vmat': ('T[0, 1, 1, 0, 0, 0, 0]', 'Rrrrs[37, 0, 0, 0]', 'T[0, -1, -1, 0, 0, 0, 0]')}]"
        # ------------------------------




if __name__ == '__main__':

    OrbTools.filter( None )

#     TestOrbInput().test__get_emb_dim()
#     TestOrbInput().test__get_deg_dim_1()
#     TestOrbInput().test__get_deg_dim_2()
#    TestOrbInput().test__get_deg_dim_3()
#    TestOrbInput().test__get_project()
#     TestOrbInput().test__get_factor_lst()
#     TestOrbInput().test__get_genus()
#     TestOrbInput().test__get_sing_lst()
#     TestOrbInput().test__get_pmz()
#     TestOrbInput().test__get_orb_bp_tree()
#     TestOrbInput().test__get_imp()
#     TestOrbInput().test__get_pmz_verify__perseus()
    TestOrbInput().test__orb_product__65_smooth()
    TestOrbInput().test__orb_product__65_sing()
Ejemplo n.º 22
0
    def test__p(self):

        OrbTools.filter(None)
        assert OrbTools.p('Hello world!') != None

        OrbTools.filter(['another_class.py'])
        assert OrbTools.p('No output since called from another class.') == None

        OrbTools.filter_unset()
        assert OrbTools.p('Filter is disabled so output this string.') != None

        OrbTools.filter_reset()
        assert OrbTools.p('Filter is enabled again so do not output.') == None

        OrbTools.filter(['test_class_orb_tools.py'])
        assert OrbTools.p('Only output if called from this class') != None
Ejemplo n.º 23
0
def CH1_cyclide():
    '''
    Creates povray image of a CH1 cyclide, which is
    an inversion of a Circular Hyperboloid of 1 sheet.    
    '''

    # Construct a trigonometric parametrization by rotating a circle.
    r, R = 1, 1
    c0, s0, c1, s1 = sage_var('c0,s0,c1,s1')
    x, y, v, w, a0 = sage_var('x,y,v,w,a0')
    q2 = sage_QQ(1) / 2
    MX = sage_matrix([(1, 0, 0), (0, c1, s1), (0, -s1, c1)])
    MXc = MX.subs({c1: a0, s1: a0})  # a0=1/sqrt(2)=cos(pi/4)=sin(pi/4)
    MZ = sage_matrix([(c1, s1, 0), (-s1, c1, 0), (0, 0, 1)])
    V = sage_vector([r * c0, 0, r * s0])
    V = MXc * V
    V[0] = V[0] + R
    pmz_AB_lst = list(MZ * V)
    OrbTools.p('V =', V)
    OrbTools.p('pmz_AB_lst =', pmz_AB_lst)
    for pmz in pmz_AB_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # Convert the trigonometric parametrization to a rational parametrization
    # We convert via the following formulas,
    #
    #     cos(s) = (y^2-x^2) / (y^2+x^2)
    #     sin(s) = 2*x*y / (y^2+x^2)
    #     y=1; x = arctan( s/2 )
    #
    C0 = (y**2 - x**2) / (y**2 + x**2)
    S0 = 2 * x * y / (y**2 + x**2)
    C1 = (w**2 - v**2) / (w**2 + v**2)
    S1 = 2 * v * w / (w**2 + v**2)
    den = (y**2 + x**2) * (w**2 + v**2)
    dct = {c0: C0, s0: S0, c1: C1, s1: S1}
    pmz_lst = [den] + [(elt.subs(dct) * den).simplify_full()
                       for elt in list(MZ * V)]
    OrbTools.p('pmz_lst =', pmz_lst)
    for pmz in pmz_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # do a basepoint analysis on the rational parametrization
    # The True argument is for resetting the number field to QQ!
    ring = PolyRing('x,y,v,w', True).ext_num_field('t^2-1/2')
    ls = LinearSeries([str(pmz) for pmz in pmz_lst], ring)
    OrbTools.p(ls.get_bp_tree())

    # construct linear series for families of conics
    ring = PolyRing(
        'x,y,v,w')  # construct polynomial ring over new ground field
    OrbTools.p(ring)
    x, y, v, w = ring.gens()
    a0, a1 = ring.root_gens()

    p1 = ['xv', (0, 2 * a0 * a1)]
    p2 = ['xv', (0, -2 * a0 * a1)]
    p3 = ['xv', (a1, 2 * a0 * a1)]
    p4 = ['xv', (-a1, -2 * a0 * a1)]

    bpt_1234 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_1234.add(p1[0], p1[1], 1)
    bpt_1234.add(p2[0], p2[1], 1)
    bpt_1234.add(p3[0], p3[1], 1)
    bpt_1234.add(p4[0], p4[1], 1)

    bpt_12 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_12.add(p1[0], p1[1], 1)
    bpt_12.add(p2[0], p2[1], 1)

    bpt_34 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_34.add(p3[0], p3[1], 1)
    bpt_34.add(p4[0], p4[1], 1)

    ls_22 = LinearSeries.get([2, 2], bpt_1234)  # |2(l1+l2)-e1-e2-e3-e4|
    ls_21 = LinearSeries.get([2, 1], bpt_1234)
    ls_12 = LinearSeries.get([1, 2], bpt_1234)
    ls_11a = LinearSeries.get([1, 1], bpt_12)
    ls_11b = LinearSeries.get([1, 1], bpt_34)

    OrbTools.p('linear series 22 =\n', ls_22)
    OrbTools.p('linear series 21 =\n', ls_21)
    OrbTools.p('linear series 12 =\n', ls_12)
    OrbTools.p('linear series 11a =\n', ls_11a)
    OrbTools.p('linear series 11b =\n', ls_11b)

    # compute reparametrization from the linear series of families
    ring = PolyRing(
        'x,y,v,w,c0,s0,c1,s1')  # construct polynomial ring with new generators
    OrbTools.p(ring)
    x, y, v, w, c0, s0, c1, s1 = ring.gens()
    a0, a1 = ring.root_gens()
    pmz_AB_lst = [1] + ring.coerce(pmz_AB_lst)
    pmz_lst = ring.coerce(pmz_lst)

    X = 1 - s0
    Y = c0
    V = 1 - s1
    W = c1
    CB_dct = {
        x: X,
        y: Y,
        v: W * X - 2 * a0 * V * Y,
        w: V * X + 2 * a0 * W * Y
    }
    pmz_CB_lst = [pmz.subs(CB_dct) for pmz in pmz_lst]  # CB  11b

    # output
    OrbTools.p('pmz_AB_lst =\n', pmz_AB_lst)
    OrbTools.p('pmz_CB_lst =\n', pmz_CB_lst)

    # approximate by map defined over rational numbers
    ci_idx = 0  # index defining the complex embedding
    OrbTools.p('complex embeddings =')
    for i in range(len(a0.complex_embeddings())):
        a0q = OrbRing.approx_QQ_coef(a0, i)
        OrbTools.p('\t\t' + str(i) + ' =', a0q, sage_n(a0q))
    pmz_AB_lst = OrbRing.approx_QQ_pol_lst(pmz_AB_lst, ci_idx)
    pmz_CB_lst = OrbRing.approx_QQ_pol_lst(pmz_CB_lst, ci_idx)

    # mathematica input
    ms = ''
    for pmz, AB in [(pmz_lst, 'ZZ'), (pmz_AB_lst, 'AB'), (pmz_CB_lst, 'CB')]:
        s = 'pmz' + AB + '=' + str(pmz) + ';'
        s = s.replace('[', '{').replace(']', '}')
        ms += '\n' + s
    OrbTools.p('Mathematica input =', ms)

    # PovInput ring cyclide
    #
    pin = PovInput()

    pin.path = './' + get_time_str() + '_CH1_cyclide/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, -5, 0)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (20, 0, 0)
    pin.shadow = True
    pin.light_lst = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (-1, 0, 0), (0, -1, 0),
                     (0, 0, -1), (10, 0, 0), (0, 10, 0), (0, 0, 10),
                     (-10, 0, 0), (0, -10, 0), (0, 0, -10)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2
    pin.height = 400
    pin.width = 800
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_AB_lst, 0)
    pin.pmz_dct['B'] = (pmz_AB_lst, 1)
    pin.pmz_dct['C'] = (pmz_CB_lst, 0)

    pin.pmz_dct['FA'] = (pmz_AB_lst, 0)
    pin.pmz_dct['FB'] = (pmz_AB_lst, 1)
    pin.pmz_dct['FC'] = (pmz_CB_lst, 0)

    v0_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]

    v1_lst_A = [(sage_QQ(i) / 180) * sage_pi for i in range(180, 360, 10)]
    v1_lst_B = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 10)]
    v1_lst_C = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 10)]

    v1_lst_FA = [(sage_QQ(i) / 180) * sage_pi for i in range(180, 360, 2)]
    v1_lst_FB = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 2)]
    v1_lst_FC = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 2)]

    prec = 50

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_lst_A,
        'prec': prec,
        'width': 0.03
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_lst_B,
        'prec': prec,
        'width': 0.03
    }
    pin.curve_dct['C'] = {
        'step0': v0_lst,
        'step1': v1_lst_C,
        'prec': prec,
        'width': 0.03
    }

    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lst_FA,
        'prec': prec,
        'width': 0.02
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lst_FB,
        'prec': prec,
        'width': 0.02
    }
    pin.curve_dct['FC'] = {
        'step0': v0_lst,
        'step1': v1_lst_FC,
        'prec': prec,
        'width': 0.02
    }

    col_A = (0.6, 0.4, 0.1, 0.0)
    col_B = (0.1, 0.15, 0.0, 0.0)
    col_C = (0.2, 0.3, 0.2, 0.0)
    colFF = (0.1, 0.1, 0.1, 0.0)

    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['C'] = [True, col_C, 'phong 0.2 phong_size 5']
    pin.text_dct['FA'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FC'] = [True, colFF, 'phong 0.2 phong_size 5']

    # raytrace image/animation
    create_pov(pin, ['A', 'B', 'C'])
    create_pov(pin, ['A', 'B', 'C', 'FA', 'FB', 'FC'])
    create_pov(pin, ['A', 'B', 'FA', 'FB'])
    create_pov(pin, ['B', 'C', 'FA', 'FB'])
Ejemplo n.º 24
0
def get_orb_bp_tree( pmz_lst ):
    '''
    Parameters
    ----------
    pmz_lst : list
        A list of 9 elements p0,...,p8 in QQ[c0,s0,c1,s1]
        such that -p0^2+p1^2+...+p8^2==0.
        Some of the polynomials can be equal to zero. 
        The list should represent a parametrization:
            S^1xS^1--->S^7.
        Here (c0,s0) is a points on S^1 such that
        thus c0^2+s0^2-1==0. Similarly for (c1,s1).
                                                                                 
    Returns
    -------
    linear_series.BasePointTree
        Base points of a parametrizing map given by the composition:
            P^1xP^1---->S^1xS^1--->S^7--->S^n          
        with 2<=n<=7. The composition of the latter two maps 
        are defined by omitting the zero polynomials from "pmz_lst". 
    '''

    # setup dictionary for reparametrization'
    #
    c0, s0, c1, s1 = OrbRing.coerce( 'c0,s0,c1,s1' )
    dct1 = {}
    dct1[c0] = '2*t0*t1/(t0^2+t1^2)'
    dct1[s0] = '(-t0^2+t1^2)/(t0^2+t1^2)'
    dct1[c1] = '2*v0*v1/(v0^2+v1^2)'
    dct1[s1] = '(-v0^2+v1^2)/(v0^2+v1^2)'
    for key in dct1: dct1[key] = OrbRing.coerce( dct1[key] )

    # apply reparametrization and multiply out denominators
    # where we only consider non-zero entries
    #
    ps_lst = [ pmz for pmz in pmz_lst if pmz != 0 ]
    gcm1 = OrbRing.coerce( '(t0^2+t1^2)*(v0^2+v1^2)' )
    ps_lst = [ OrbRing.coerce( ps.subs( dct1 ) * gcm1 ) for ps in ps_lst ]

    # ensure that polynomials are co-prime
    #
    gcd1 = sage_gcd( ps_lst )
    ps_lst = [ OrbRing.coerce( ps / gcd1 ) for ps in ps_lst ]
    OrbTools.p( 'gcd =', gcd1 )
    OrbTools.p( 'ps_lst =', ps_lst )

    # Verify whether "ps_lst" represents a map P^1xP^1--->S^n
    # where "n==len(ps_lst)".
    #
    sum1 = sum( [-ps_lst[0] ** 2] + [ ps ** 2 for ps in ps_lst[1:] ] )
    OrbTools.p( 'sum =', sum1 )
    if sum1 != 0:
        warnings.warn( 'Warning: Not parametrization of surface in S^7: ' + str( sum1 ), )

    # set coordinates x,y,v,w
    #
    t0, t1, v0, v1 = OrbRing.coerce( 't0,t1,v0,v1' )
    dct2 = {}
    dct2[t0] = sage_var( 'x' )
    dct2[t1] = sage_var( 'y' )
    dct2[v0] = sage_var( 'v' )
    dct2[v1] = sage_var( 'w' )
    xyvw_lst = [ str( ps.subs( dct2 ) ) for ps in ps_lst ]

    #
    # Compute base point tree using "linear_series" package
    #
    ls = LinearSeries( xyvw_lst, PolyRing( 'x,y,v,w', True ) )
    bp_tree = ls.get_bp_tree()
    OrbTools.p( ls )
    OrbTools.p( bp_tree )

    return bp_tree
Ejemplo n.º 25
0
def get_xmat(r_str):
    '''
    Parameters
    ----------
    r_str : string 
        A string of the following format:
            'X[%,%,%]'
        where % denotes an integer in [0,360].
                    
    Returns
    -------
    sage_matrix
        A matrix corresponding to the map S^7--->S^7 that is the 
        composition of the following rotation matrices.
          
            Angle 1:
                [  1   0   0   0   0   0   0   0   0]
                [  0  c0 -s0   0   0   0   0   0   0]
                [  0  s0  c0   0   0   0   0   0   0]
                [  0   0   0   1   0   0   0   0   0]
                [  0   0   0   0   1   0   0   0   0]
                [  0   0   0   0   0   1   0   0   0]
                [  0   0   0   0   0   0   1   0   0]
                [  0   0   0   0   0   0   0   1   0]
                [  0   0   0   0   0   0   0   0   1] 

            Angle 2:
                [  1   0   0   0   0   0   0   0   0]
                [  0  c0   0 -s0   0   0   0   0   0]
                [  0   0   1   0   0   0   0   0   0]
                [  0  s0   0  c0   0   0   0   0   0]
                [  0   0   0   0   1   0   0   0   0]
                [  0   0   0   0   0   1   0   0   0]
                [  0   0   0   0   0   0   1   0   0]
                [  0   0   0   0   0   0   0   1   0]
                [  0   0   0   0   0   0   0   0   1] 
            
            Angle 3:
                [  1   0   0   0   0   0   0   0   0]
                [  0   1   0   0   0   0   0   0   0]
                [  0   0  c0 -s0   0   0   0   0   0]
                [  0   0  s0  c0   0   0   0   0   0]
                [  0   0   0   0   1   0   0   0   0]
                [  0   0   0   0   0   1   0   0   0]
                [  0   0   0   0   0   0   1   0   0]
                [  0   0   0   0   0   0   0   1   0]
                [  0   0   0   0   0   0   0   0   1]                 
    '''

    # parse input string
    #
    if r_str[0] != 'X':
        raise ValueError('Incorrect format of input: ', r_str)
    r_lst = sage__eval(r_str[1:])
    if len(r_lst) != 3:
        raise ValueError('Incorrect format of input: ', r_str)

    # mat1
    #
    a_lst = [r_lst[0], 0, 0, 0]
    mat1 = get_rmat('Rrppp' + str(a_lst))
    OrbTools.p('mat1 =\n' + str(get_omat('Orppp')))

    # mat2
    #
    a_lst = [r_lst[1], 0, 0, 0]
    e_lst = [1, 3, 2, 4, 5, 6, 7, 8]
    eI_lst = sage_Permutation(e_lst).inverse()
    m_tup = ('E' + str(eI_lst), 'Rrppp' + str(a_lst), 'E' + str(e_lst))
    mat2 = get_mat(*m_tup)
    m_tup = ('E' + str(eI_lst), 'Orppp', 'E' + str(e_lst))
    OrbTools.p('mat2 =\n' + str(get_mat(*m_tup)))

    # mat3
    #
    a_lst = [0, r_lst[2], 0, 0]
    e_lst = [1, 4, 2, 3, 5, 6, 7, 8]
    eI_lst = sage_Permutation(e_lst).inverse()
    m_tup = ('E' + str(eI_lst), 'Rprpp' + str(a_lst), 'E' + str(e_lst))
    mat3 = get_mat(*m_tup)
    m_tup = ('E' + str(eI_lst), 'Oprpp', 'E' + str(e_lst))
    OrbTools.p('mat3 =\n' + str(get_mat(*m_tup)))

    return mat3 * mat2 * mat1
Ejemplo n.º 26
0
def get_curve_lst( pin, fam ):
    '''
    Parameters
    ----------
    pin : PovInput
        The following attributes of the PovInput object are used:
        * "pin.pmz_dct"
        * "pin.scale"
        * "pin.curve_dct"
        * "pin.curve_lst_dct"
                                         
    fam : string 
        A key string for a family id (eg. 'A').
        
    Returns
    -------
    list
        Returns a list of lists of points. Each list of points
        defines points on a curve. v1_lstD
        
        Returns "pin.curve_lst_dct[<fam>]"  if 
            "pin.curve_lst_dct[<fam>]!=None". 
    
        Otherwise let us assume w.l.o.g. that "fam=='A'"
        such that "pin.curve_lst_dct['A']==None".          
        
        We set "pin.curve_lst_dct['A']" as follows:
            pin.curve_lst_dct['A'] = [ <curveA<0>>, <curveA<1>>, ... ]            
        where           
          * <curveA<n>> is a list of points 
                [x,y,z] 
            on a curve in family with id 'A', which are 
            scaled with "pin.scale". 
          
          * The space between points in <curveA<n>> is 
            determined by "pin.curve_dct['A']['step0']".

          * The space between <curveA<n>> and <curveA<n+1>> is  
            determined by values in "pin.curve_dct['A']['step1']".

          * The precision of points in <curveA<n>> is 
            determined by values in "pin.curve_dct['A']['prec']".          
          
        Returns pin.curve_lst_dct['A'].
    '''

    OrbTools.p( fam )

    if fam in pin.curve_lst_dct and pin.curve_lst_dct[fam] != None:
        OrbTools.p( 'Already computed ', fam )
        return pin.curve_lst_dct[fam]

    pmz_lst, fam_id = pin.pmz_dct[fam]
    pmz_lst = OrbRing.coerce( pmz_lst )

    # loop through lists of parameter values
    pin.curve_lst_dct[fam] = []
    for v1 in pin.curve_dct[fam]['step1']:
        curve = []
        for v0 in pin.curve_dct[fam]['step0']:

            if fam_id == 0:
                point = get_pmz_value( pmz_lst, v0, v1, pin.curve_dct[fam]['prec'] )
            elif fam_id == 1:
                point = get_pmz_value( pmz_lst, v1, v0, pin.curve_dct[fam]['prec'] )
            else:
                raise ValueError( 'Expect pin.pmz_dct[fam][1] in [0,1]: ', fam_id )

            # add points to curve if map is defined
            if point != None:
                point = [ coord * pin.scale for coord in point  ]
                curve += [point]


        # need at least 3 points for cubic interpolation
        if len( curve ) >= 3:

            # add curve to family
            pin.curve_lst_dct[fam] += [curve]

    return pin.curve_lst_dct[fam]
Ejemplo n.º 27
0
def get_pt_dct(fname='cos_sin'):
    '''
    Reads in a list of Pythagorian triples, which was obtained from:
    <http://www.tsm-resources.com/alists/PythagTriples.txt>
    
    Parameters
    ----------
    fname: string
        Name of file without extention
        The file should contain 3 integers on each line separated by spaces. 
        We expect them to be Pythagorian triples.
        
    Returns
    -------
    dict
        A dictionary 
            { 
                angle : [a,b,c],
                ... 
            }
        where a^2+b^2=c^2 and <angle> corresponds to 
            round(arctan( <b>/<a> )*180/pi)
        The key <angle> runs from 1 to 89 degrees.           
    '''

    key = 'cossin'
    if key in OrbTools.get_tool_dct():
        return OrbTools.get_tool_dct()[key]

    path = os.path.dirname(os.path.abspath(__file__)) + '/'
    file_name = path + fname
    OrbTools.p('Calculating Pythagorian triples and angles from:', file_name)

    angle_lst = []
    pt_dct = {}
    with open(file_name + '.txt', 'r') as f:
        for line in f:
            ps_lst = line.replace('\r\n', '').split()
            pt0 = [sage_QQ(ps) for ps in ps_lst]  # need to be divisable!

            # Try all combinations
            # while a triple is still small.
            # We assume that the Pythagorian triples are
            # ordered on coefficient size in the input file.
            #
            pt1a = [pt0[0], pt0[1], pt0[2]]
            pt1b = [-pt0[0], pt0[1], pt0[2]]
            pt1c = [pt0[0], -pt0[1], pt0[2]]
            pt1d = [-pt0[0], -pt0[1], pt0[2]]

            pt2a = [pt0[1], pt0[0], pt0[2]]
            pt2b = [-pt0[1], pt0[0], pt0[2]]
            pt2c = [pt0[1], -pt0[0], pt0[2]]
            pt2d = [-pt0[1], -pt0[0], pt0[2]]

            for pt in [pt1a, pt1b, pt1c, pt1d, pt2a, pt2b, pt2c, pt2d]:

                if pt[0]**2 + pt[1]**2 != pt[2]**2:
                    raise ValueError(
                        'Expect a file containing Pythagorian triples:', pt)

                # cos = pt[0]/pt[2], sin = pt[1]/pt[2], tan=sin/cos
                angle = round(sage_arctan(pt[1] / pt[0]) * 180 / sage_pi)

                if angle not in angle_lst and angle > 0:
                    angle_lst += [angle]
                    pt_dct.update({angle: pt})

    OrbTools.p(len(pt_dct.keys()))

    OrbTools.get_tool_dct()[key] = pt_dct
    OrbTools.save_tool_dct()

    return pt_dct
Ejemplo n.º 28
0
def ring_cyclide():
    '''
    Creates povray image of 4 families of circles on a ring cyclide. 
    '''

    # We construct a trigonometric parametrization of the ring cyclide,
    # by rotating a circle of radius r along a circle of radius R.
    R = 2
    r = 1
    x, y, v, w, c0, s0, c1, s1 = sage_var('x,y,v,w,c0,s0,c1,s1')
    V = sage_vector([r * c0 + R, 0, r * s0])
    M = sage_matrix([(c1, -s1, 0), (s1, c1, 0), (0, 0, 1)])
    pmz_AB_lst = [1] + list(M * V)
    OrbTools.p('pmz_AB_lst =', pmz_AB_lst)
    for pmz in pmz_AB_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # convert pmz_AB_lst to rational parametrization pmz_lst
    C0 = (y**2 - x**2) / (y**2 + x**2)
    S0 = 2 * x * y / (y**2 + x**2)
    C1 = (w**2 - v**2) / (w**2 + v**2)
    S1 = 2 * v * w / (w**2 + v**2)
    den = (y**2 + x**2) * (w**2 + v**2)
    dct = {c0: C0, s0: S0, c1: C1, s1: S1}
    pmz_lst = [den] + [(elt.subs(dct) * den).simplify_full()
                       for elt in list(M * V)]
    OrbTools.p('pmz_lst =', pmz_lst)

    # find basepoints
    ls = LinearSeries(pmz_lst, PolyRing('x,y,v,w', True))
    OrbTools.p(ls.get_bp_tree())

    # construct linear series for families of conics
    a0, a1 = PolyRing('x,y,v,w').ext_num_field('t^2+1/3').ext_num_field(
        't^2+1').root_gens()

    p1 = ['xv', (-a0, a1)]
    p2 = ['xv', (a0, -a1)]
    p3 = ['xv', (-a0, -a1)]
    p4 = ['xv', (a0, a1)]

    bpt_1234 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_1234.add(p1[0], p1[1], 1)
    bpt_1234.add(p2[0], p2[1], 1)
    bpt_1234.add(p3[0], p3[1], 1)
    bpt_1234.add(p4[0], p4[1], 1)

    bpt_12 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_12.add(p1[0], p1[1], 1)
    bpt_12.add(p2[0], p2[1], 1)

    bpt_34 = BasePointTree(['xv', 'xw', 'yv', 'yw'])
    bpt_34.add(p3[0], p3[1], 1)
    bpt_34.add(p4[0], p4[1], 1)

    ls_22 = LinearSeries.get([2, 2], bpt_1234)  # |2(l1+l2)-e1-e2-e3-e4|
    ls_21 = LinearSeries.get([2, 1], bpt_1234)
    ls_12 = LinearSeries.get([1, 2], bpt_1234)
    ls_11a = LinearSeries.get([1, 1], bpt_12)
    ls_11b = LinearSeries.get([1, 1], bpt_34)

    OrbTools.p('linear series 22 =\n', ls_22)
    OrbTools.p('linear series 21 =\n', ls_21)
    OrbTools.p('linear series 12 =\n', ls_12)
    OrbTools.p('linear series 11a =\n', ls_11a)
    OrbTools.p('linear series 11b =\n', ls_11b)

    # compute reparametrization
    ring = PolyRing(
        'x,y,v,w,c0,s0,c1,s1')  # construct polynomial ring with new generators
    pmz_lst = ring.coerce(pmz_lst)
    x, y, v, w, c0, s0, c1, s1 = ring.gens()
    X = 1 - s0
    Y = c0
    # see get_S1xS1_pmz()
    V = 1 - s1
    W = c1
    q = sage_n(sage_sqrt(3)).exact_rational()  # approximation of sqrt(3)
    CB_dct = {x: X, y: Y, v: W * X + q * V * Y, w: V * X - q * W * Y}
    DB_dct = {x: X, y: Y, v: W * X - q * V * Y, w: V * X + q * W * Y}
    pmz_CB_lst = [pmz.subs(CB_dct) for pmz in pmz_lst]
    pmz_DB_lst = [pmz.subs(DB_dct) for pmz in pmz_lst]

    # output
    OrbTools.p('pmz_AB_lst =\n', pmz_AB_lst)
    OrbTools.p('pmz_CB_lst =\n', pmz_CB_lst)
    OrbTools.p('pmz_DB_lst =\n', pmz_DB_lst)

    # mathematica
    for pmz, AB in [(pmz_AB_lst, 'AB'), (pmz_CB_lst, 'CB'),
                    (pmz_DB_lst, 'DB')]:
        s = 'pmz' + AB + '=' + str(pmz) + ';'
        s = s.replace('[', '{').replace(']', '}')
        print(s)

    # PovInput ring cyclide
    #
    pin = PovInput()

    pin.path = './' + get_time_str() + '_ring_cyclide/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, -7, 0)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (55, 0, 0)  # 45
    pin.shadow = True
    pin.light_lst = [(0, 0, -5), (0, -5, 0), (-5, 0, 0), (0, 0, 5), (0, 5, 0),
                     (5, 0, 0), (-5, -5, -5), (5, -5, 5), (-5, -5, 5),
                     (5, -5, -5)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2
    pin.width = 800
    pin.height = 400
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_AB_lst, 0)
    pin.pmz_dct['B'] = (pmz_AB_lst, 1)
    pin.pmz_dct['C'] = (pmz_CB_lst, 0)
    pin.pmz_dct['D'] = (pmz_DB_lst, 0)
    pin.pmz_dct['FA'] = (pmz_AB_lst, 0)
    pin.pmz_dct['FB'] = (pmz_AB_lst, 1)
    pin.pmz_dct['FC'] = (pmz_CB_lst, 0)
    pin.pmz_dct['FD'] = (pmz_DB_lst, 0)
    pin.pmz_dct['WA'] = (pmz_AB_lst, 0)
    pin.pmz_dct['WB'] = (pmz_AB_lst, 1)
    pin.pmz_dct['WC'] = (pmz_CB_lst, 0)
    pin.pmz_dct['WD'] = (pmz_DB_lst, 0)

    v0_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]
    v1_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 24)]

    v1_lst_A = [
        sage_pi / 2 + (sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 12)
    ]
    v1_lstFF = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 1)]

    v1_lst_WA = [
        0.1, 0.52, 0.94, 1.36, 1.78, 2.2, 2.61, 3.04, 3.45, 3.88, 4.3, 4.712,
        5.13, 5.55, 5.965
    ]
    v1_lst_WB = [
        0, 0.7, 1.31, 1.8, 2.18, 2.5, 2.77, 3.015, 3.26, 3.51, 3.78, 4.099,
        4.49, 4.97, 5.579
    ]
    v1_lst_WD = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 24)]
    v1_lst_WC = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 24)]

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_lst_A,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_lst,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['C'] = {
        'step0': v0_lst,
        'step1': v1_lst,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['D'] = {
        'step0': v0_lst,
        'step1': v1_lst,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lstFF,
        'prec': 10,
        'width': 0.02
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lstFF,
        'prec': 10,
        'width': 0.02
    }
    pin.curve_dct['FC'] = {
        'step0': v0_lst,
        'step1': v1_lstFF,
        'prec': 10,
        'width': 0.02
    }
    pin.curve_dct['FD'] = {
        'step0': v0_lst,
        'step1': v1_lstFF,
        'prec': 10,
        'width': 0.02
    }
    pin.curve_dct['WA'] = {
        'step0': v0_lst,
        'step1': v1_lst_WA,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['WB'] = {
        'step0': v0_lst,
        'step1': v1_lst_WB,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['WC'] = {
        'step0': v0_lst,
        'step1': v1_lst_WC,
        'prec': 10,
        'width': 0.05
    }
    pin.curve_dct['WD'] = {
        'step0': v0_lst,
        'step1': v1_lst_WD,
        'prec': 10,
        'width': 0.05
    }

    # A = | rotated circle
    # B = - horizontal circle
    # C = / villarceau circle
    # D = \ villarceau circle
    col_A = rgbt2pov((28, 125, 154, 0))  # blue
    col_B = rgbt2pov((74, 33, 0, 0))  # brown
    col_C = rgbt2pov((75, 102, 0, 0))  # green
    col_D = rgbt2pov((187, 46, 0, 0))  # red/orange
    colFF = rgbt2pov((179, 200, 217, 0))  # light blue

    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['C'] = [True, col_C, 'phong 0.2 phong_size 5']
    pin.text_dct['D'] = [True, col_D, 'phong 0.2 phong_size 5']
    pin.text_dct['FA'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FC'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FD'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['WA'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['WB'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['WC'] = [True, col_C, 'phong 0.2 phong_size 5']
    pin.text_dct['WD'] = [True, col_D, 'phong 0.2 phong_size 5']

    # raytrace image/animation
    create_pov(pin, ['A', 'C', 'D'])
    create_pov(pin, ['A', 'C', 'D'] + ['FA', 'FC', 'FD'])

    create_pov(pin, ['WA', 'WB', 'WC', 'WD'])
    create_pov(pin, ['WA', 'WB', 'WC', 'WD'] + ['FA', 'FC', 'FD'])

    create_pov(pin, ['WA', 'WB', 'WD'])
    create_pov(pin, ['WA', 'WB', 'WD'] + ['FA', 'FC', 'FD'])
Ejemplo n.º 29
0
def spindle_cyclide():
    '''
    Constructs a povray image of a spindle cyclide. The spindle cyclide is
    an inversion of a circular cylinder.
    '''

    # We construct a trigonometric parametrization
    # of the cyclide by rotating a circle.
    #
    r = 1
    R = 1
    # radii of circles
    x, y, v, w = sage_var('x,y,v,w')
    c0, s0, c1, s1 = sage_var('c0,s0,c1,s1')
    V = sage_vector([r * c0 + R, 0, r * s0])
    M = sage_matrix([(c1, -s1, 0), (s1, c1, 0), (0, 0, 1)])
    pmz_AB_lst = [1] + list(M * V)
    OrbTools.p('pmz_AB_lst =', pmz_AB_lst)
    for pmz in pmz_AB_lst:
        OrbTools.p('\t\t', sage_factor(pmz))

    # PovInput spindle cyclide
    #
    pin = PovInput()

    pin.path = './' + get_time_str() + '_spindle_cyclide/'
    pin.fname = 'orb'
    pin.scale = 1
    pin.cam_dct['location'] = (0, -5, 0)
    pin.cam_dct['lookat'] = (0, 0, 0)
    pin.cam_dct['rotate'] = (45, 0, 0)
    pin.shadow = True
    pin.light_lst = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (-1, 0, 0), (0, -1, 0),
                     (0, 0, -1), (10, 0, 0), (0, 10, 0), (0, 0, 10),
                     (-10, 0, 0), (0, -10, 0), (0, 0, -10)]
    pin.axes_dct['show'] = False
    pin.axes_dct['len'] = 1.2
    pin.height = 400
    pin.width = 800
    pin.quality = 11
    pin.ani_delay = 10

    pin.impl = None

    pin.pmz_dct['A'] = (pmz_AB_lst, 0)
    pin.pmz_dct['B'] = (pmz_AB_lst, 1)

    pin.pmz_dct['FA'] = (pmz_AB_lst, 0)
    pin.pmz_dct['FB'] = (pmz_AB_lst, 1)

    v0_lst = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 360, 10)]

    v1_lst_A = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 270, 15)]
    v1_lst_B = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 15)]

    v1_lstFA = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 270 - 15, 1)]
    v1_lstFB = [(sage_QQ(i) / 180) * sage_pi for i in range(0, 180, 1)]

    pin.curve_dct['A'] = {
        'step0': v0_lst,
        'step1': v1_lst_A,
        'prec': 10,
        'width': 0.03
    }
    pin.curve_dct['B'] = {
        'step0': v0_lst,
        'step1': v1_lst_B,
        'prec': 10,
        'width': 0.03
    }
    pin.curve_dct['FA'] = {
        'step0': v0_lst,
        'step1': v1_lstFA,
        'prec': 10,
        'width': 0.02
    }
    pin.curve_dct['FB'] = {
        'step0': v0_lst,
        'step1': v1_lstFB,
        'prec': 10,
        'width': 0.02
    }

    col_A = (0.6, 0.4, 0.1, 0.0)
    col_B = (0.1, 0.15, 0.0, 0.0)
    colFF = (0.1, 0.1, 0.1, 0.0)
    pin.text_dct['A'] = [True, col_A, 'phong 0.2 phong_size 5']
    pin.text_dct['B'] = [True, col_B, 'phong 0.2 phong_size 5']
    pin.text_dct['FA'] = [True, colFF, 'phong 0.2 phong_size 5']
    pin.text_dct['FB'] = [True, colFF, 'phong 0.2 phong_size 5']

    # raytrace image/animation
    create_pov(pin, ['A', 'B'])
    create_pov(pin, ['A', 'B', 'FA', 'FB'])
Ejemplo n.º 30
0
    for i in range(len(C)):
        s = str(C[i])
        for (a, b) in [('a0', 'sqrt(1/2)'), ('k', 'p1'), ('x0', '1'),
                       ('x1', 'x'), ('x2', 'y'), ('x3', 'z')]:
            s = s.replace(a, b)
        print(s)


if __name__ == '__main__':

    # Debug output settings
    #
    sage_set_verbose(-1)
    mod_lst = []
    mod_lst += ['__main__.py']
    OrbTools.filter(mod_lst)  # output only from specified modules
    # OrbTools.filter( None )  # print all verbose output, comment to disable.
    OrbTools.start_timer()

    # set environment variables for output, Maple and Magma
    # Maple and Magma are optionally used in orbital.prod.orb_product.
    if 'OUTPUT_PATH' not in os.environ:
        os.environ[
            'OUTPUT_PATH'] = '/home/niels/Desktop/n/src/output/orb/povray/'
    os.environ[
        'PATH'] += os.pathsep + '/home/niels/Desktop/n/app/maple/link/bin'
    os.environ['PATH'] += os.pathsep + '/home/niels/Desktop/n/app/magma/link'

    #########################################
    #                                       #
    # (Un)comment one or more use cases     #