Differences between revisions 29 and 35 (spanning 6 versions)
Revision 29 as of 2013-09-10 17:34:26
Size: 18441
Editor: dch252
Comment:
Revision 35 as of 2019-11-15 08:17:23
Size: 18331
Editor: chapoton
Comment: py3 print
Deletions are marked like this. Additions are marked like this.
Line 85: Line 85:
by Antonio Valdés and Pablo Angulo. A first interact allows the user to introduce a parametric surface, and draws it. Then a second interact draws a geodesic within the surface. The separation is so that after the first interact, the geodesic equations are "compiled", and then the second interact is faster.
{{{#!sagecell
u, v, t = var('u v t')
by Antonio Valdés and Pablo Angulo. This example was originally composed of two interacts:
 - the first allowing the user to introduce a parametric surface, and draw it.
 - the second drawing a geodesic within the surface.
The separation was so that after the first interact, the geodesic equations were "compiled", thus making the second interact faster.

This still looks as a good idea to me, so please read the original code at https://malabares.cancamusa.net/home/pub/14/
But the following is fixed so that there is only one interact, and sagecell works. There might be another way yto

{{{#!sagecell
from scipy.integrate import odeint

u, v, t, du, dv = var('u v t du dv')

def fading_line3d(points, rgbcolor1, rgbcolor2, *args, **kwds):
    L = len(points)
    vcolor1 = vector(RDF, rgbcolor1)
    vcolor2 = vector(RDF, rgbcolor2)
    return sum(line3d(points[j:j+2],
                      rgbcolor = tuple( ((L-j)/L)*vcolor1 + (j/L)*vcolor2 ),
                      *args, **kwds)
               for j in srange(L-1))

steps = 100
Line 92: Line 113:
      _int_u = input_grid(1, 2, default = [[0,pi]], label = 'u -interval'),
      _int_v = input_grid(1, 2, default = [[-pi,pi]], label = 'v -interval')):
    
    global F, Fu, Fv, func, S_plot, int_u, int_v
    int_u = _int_u[0]
    int_v = _int_v[0]
      int_u = input_grid(1, 2, default = [[0,pi]], label = 'u -interval'),
      int_v = input_grid(1, 2, default = [[-pi,pi]], label = 'v -interval'),
      init_point = input_grid(1, 2, default = [[-pi/4,pi/8]], label = 'coordinates of \ninitial point'),
      init_vector = input_grid(1, 2, default = [[1,0]], label = 'coordinates of \ninitial vector'),
      int_s = slider(0, 10, 1/10,
                           default = pi/2,
                           label = 'geodesic interval'),
      sliding_color = checkbox(True,'change color along the geodesic')):

    int_u = int_u[0]
    int_v = int_v[0]
    u_0, v_0 = init_point[0]
    V_u, V_v = init_vector[0]
Line 104: Line 132:
    S_plot.show(aspect_ratio = [1, 1, 1])
    
   
Line 143: Line 170:

# second interact
from scipy.integrate import odeint

def fading_line3d(points, rgbcolor1, rgbcolor2, *args, **kwds):
    L = len(points)
    vcolor1 = vector(RDF, rgbcolor1)
    vcolor2 = vector(RDF, rgbcolor2)
    return sum(line3d(points[j:j+2],
                      rgbcolor = tuple( ((L-j)/L)*vcolor1 + (j/L)*vcolor2 ),
                      *args, **kwds)
               for j in srange(L-1))

steps = 100

@interact
def _(u_0 = slider(int_u[0], int_u[1], (int_u[1] - int_u[0])/100,
                   default = (int_u[0] + int_u[1])/2, label = 'u_0'),
      v_0 = slider(int_v[0], int_v[1], (int_v[1] - int_v[0])/100,
                   default = (int_v[0] + int_v[1])/2, label = 'v_0'),
      V_u = slider(-10, 10, 1/10, default = 1, label = 'V_u'),
      V_v = slider(-10, 10, 1/10, default = 0, label = 'V_v'),
      int_s = slider(0, 10, 1/10,
                           default = (int_u[1] - int_u[0])/2,
                           label = 'geodesic interval'),
      sliding_color = checkbox(True,'change color along the geodesic')):
        
        du, dv, u, v = var('du dv u v')
        Point = [u_0, v_0]
        velocity = [V_u, V_v]
        Point = map(float, Point)
        velocity = map(float, velocity)
        
        geo2D_aux = odeint(func,
                           y0 = [velocity[0], velocity[1], Point[0], Point[1]],
                           t = srange(0, int_s, 0.01))
    
        geo3D = [F(u=l,v=r) for [j, k, l, r] in geo2D_aux]
        
        if sliding_color:
            g_plot = fading_line3d(geo3D, rgbcolor1 = (1, 0, 0), rgbcolor2 = (0, 1, 0), thickness=4)
        else:
            g_plot = line3d(geo3D, rgbcolor=(0, 1, 0), thickness=4)
        
        P = F(u=Point[0], v=Point[1])
        P_plot = point3d((P[0], P[1], P[2]), rgbcolor = (0, 0, 0), pointsize = 30)
        V = velocity[0] * Fu(u = Point[0], v = Point[1]) + \
            velocity[1] * Fv(u= Point[0], v = Point[1])
        V_plot = arrow3d(P, P + V, color = 'black')
        
        show(g_plot + S_plot + V_plot + P_plot,aspect_ratio = [1, 1, 1])
             Point = [u_0, v_0]
    velocity = [V_u, V_v]
    Point = map(float, Point)
    velocity = map(float, velocity)
    
    geo2D_aux = odeint(func,
                       y0 = [velocity[0], velocity[1], Point[0], Point[1]],
                       t = srange(0, int_s, 0.01))
    
    geo3D = [F(u=l,v=r) for [j, k, l, r] in geo2D_aux]
    
    if sliding_color:
        g_plot = fading_line3d(geo3D, rgbcolor1 = (1, 0, 0), rgbcolor2 = (0, 1, 0), thickness=4)
    else:
        g_plot = line3d(geo3D, rgbcolor=(0, 1, 0), thickness=4)
    
    P = F(u=Point[0], v=Point[1])
    P_plot = point3d((P[0], P[1], P[2]), rgbcolor = (0, 0, 0), pointsize = 30)
    V = velocity[0] * Fu(u = Point[0], v = Point[1]) + \
        velocity[1] * Fv(u= Point[0], v = Point[1])
    V_plot = arrow3d(P, P + V, color = 'black')
    
    show(g_plot + S_plot + V_plot + P_plot,aspect_ratio = [1, 1, 1])
Line 210: Line 210:
            print 'Vertices:', len(g.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(g.edges()), ('(%s*(%s/2))' %(len(g.vertices()), Dimension) if Calculations else '')             print('Vertices:', len(g.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(g.edges()), ('(%s*(%s/2))' %(len(g.vertices()), Dimension) if Calculations else ''))
Line 215: Line 215:
            print 'Vertices:', len(g.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(g.edges()), ('(%s*(%s/2))' %(len(g.vertices()), Dimension) if Calculations else '')             print('Vertices:', len(g.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(g.edges()), ('(%s*(%s/2))' %(len(g.vertices()), Dimension) if Calculations else ''))
Line 222: Line 222:
            print 'Vertices:', len(s.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(s.edges()), ('(%s*(%s/2))' %(len(s.vertices()), Dimension) if Calculations else '')             print('Vertices:', len(s.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(s.edges()), ('(%s*(%s/2))' %(len(s.vertices()), Dimension) if Calculations else ''))
Line 227: Line 227:
            print 'Vertices:', len(s.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(s.edges()), ('(%s*(%s/2))' %(len(s.vertices()), Dimension) if Calculations else '')             print('Vertices:', len(s.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(s.edges()), ('(%s*(%s/2))' %(len(s.vertices()), Dimension) if Calculations else ''))
Line 233: Line 233:
            print 'Vertices:', len(d.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(d.edges()), ('(%s*(%s/2))' %(len(d.vertices()), Dimension) if Calculations else '')             print('Vertices:', len(d.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(d.edges()), ('(%s*(%s/2))' %(len(d.vertices()), Dimension) if Calculations else ''))
Line 238: Line 238:
            print 'Vertices:', len(d.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(d.edges()), ('(%s*(%s/2))' %(len(d.vertices()), Dimension) if Calculations else '')             print('Vertices:', len(d.vertices()), ('(2^%s)'%Dimension if Calculations else ''), '\nEdges:', len(d.edges()), ('(%s*(%s/2))' %(len(d.vertices()), Dimension) if Calculations else ''))
Line 311: Line 311:
                      for j in xrange(partes-1))                       for j in range(partes - 1))
Line 330: Line 330:
    print 'Number of lines with k intersection points:'
    print ', '.join('%d:%d'%(k,v) for k,v in d.iteritems())
    print('Number of lines with k intersection points:')
    print(', '.join('%d:%d' % kv for kv in d.items()))
Line 352: Line 352:
    print 'A curve of lenght %f'%longitud((curvax, curvay), t0, t1)     print('A curve of lenght %f'%longitud((curvax, curvay), t0, t1))
Line 355: Line 355:
    print 'Approx length using Crofton\'s formula: %f'%((cortes_tot/L)*(pi*M))     print('Approx length using Crofton\'s formula: %f'%((cortes_tot/L)*(pi*M)))
Line 419: Line 419:
    print 'Number of lines with linking number k:'
    print ', '.join('%d:%d'%(k,v) for k,v in d.iteritems())
    print('Number of lines with linking number k:')
    print(', '.join('%d:%d' % kv for kv in d.items()))
Line 434: Line 434:
    print 'Bahnchoff-Pohl area of the curve(aprox): %f'%bp_area_aprox     print('Bahnchoff-Pohl area of the curve(aprox): %f' % bp_area_aprox)

Sage Interactions - Geometry

goto interact main page

Intersecting tetrahedral reflections FIXME

by Marshall Hampton. Inspired by a question from Hans Schepker of Glass Geometry.

tetrareflect.png

Evolutes

by Pablo Angulo. Computes the evolute of a plane curve given in parametric coordinates. The curve must be parametrized from the interval [0,2pi].

evoluta3.png

Geodesics on a parametric surface

by Antonio Valdés and Pablo Angulo. This example was originally composed of two interacts:

  • - the first allowing the user to introduce a parametric surface, and draw it. - the second drawing a geodesic within the surface.

The separation was so that after the first interact, the geodesic equations were "compiled", thus making the second interact faster.

This still looks as a good idea to me, so please read the original code at https://malabares.cancamusa.net/home/pub/14/ But the following is fixed so that there is only one interact, and sagecell works. There might be another way yto

geodesics1.png geodesics2.png

Dimensional Explorer

By Eviatar Bach

Renders 2D images (perspective or spring-layout) and 3D models of 0-10 dimensional hypercubes. It also displays number of edges and vertices.

dimensions.png

Crofton's formula

by Pablo Angulo. Illustrates Crofton's formula by throwing some random lines and computing the intersection number with a given curve. May use either solve for exact computation of the intersections, or may also approximate the curve by straight segments (this is the default).

crofton4.png

Banchoff-Pohl area

by Pablo Angulo. Computes the Banchoff-Pohl "area enclosed by a spatial curve", by throwing some random lines and computing the linking number with the given curve. Lines not linked to the given curve are displayed in red, linked lines are displayed in green.

banchoff-pohl.png

interact/geometry (last edited 2023-08-30 08:21:15 by pang)