Discrete Geometry in Sage (DGCI - April 7th, 2011)

Graphics Capabilities of Sage

Many of the example of this section are taken from Sage Documentation : http://sagemath.org/doc

2d plots

The following plotting functions are supported:

Dessiner une fonction $\mathbb{R}\mapsto \mathbb{R}$ : la commande plot:

{{{id=0| x,y = var('x y') plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3)) /// }}} {{{id=1| f(x) = x^4 - 1 complex_plot(f, (-2,2), (-2,2)) /// }}}

2d primitives

The following graphics primitives are supported:

{{{id=2| f = sin(1/x) P = plot(f, -10, 10, color='red') P /// }}} {{{id=3| Q = line([(3,0.9), (7,0.9), (7,1.1), (3,1.1), (3,0.9)], color='green') Q /// }}} {{{id=4| R = text('$f(x) = \\sin(\\frac{1}{x})$', (5,1)) R /// }}} {{{id=5| P + Q + R /// }}}

For more examples on 2D ploting, visit: http://sagemath.org/doc/reference/plotting.html

3d plots

Dessiner une fonction $\mathbb{R}^2\mapsto \mathbb{R}$ : la commande plot3d:

{{{id=6| def f(x, y): return x^2 + y^2 plot3d(f, (-10,10), (-10,10), viewer='tachyon') /// }}}

the same with Jmol:

{{{id=7| plot3d(f, (-10,10), (-10,10)) /// }}}

A hyperboloid:

{{{id=8| x, y, z = var('x, y, z') implicit_plot3d(x^2 + y^2 - z^2 -0.3, (x, -2, 2), (y, -2, 2), (z, -1.8, 1.8)) /// }}}

A torus:

{{{id=9| implicit_plot3d((sqrt(x*x+y*y)-3)^2 + z*z - 1, (x, -4, 4), (y, -4, 4), (z, -1, 1)) /// }}}

3D primitives

Two spheres touching:

{{{id=10| sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=[1,1,1]) /// }}}

A transparent thick green line and a little blue line:

{{{id=11| A = line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, color='green') B = line3d([(0,1,0), (1,0,2)]) A + B /// }}} {{{id=12| from sage.plot.plot3d.shapes2 import ruler R = ruler([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); R /// }}}

For more examples on 3D ploting, visit: http://sagemath.org/doc/reference/plot3d.html

Discrete Geometry using Sage

(The following is not in Sage currently but could be soon if there is an interest).

You can email me to get the file if you want. Or I will post it on my web site. Anyhow, this will get into Sage in the near future.

{{{id=13| load /Users/slabbe/Documents/Projets/laber/discrete_object.sage /// }}}

Discrete planes

{{{id=14| P = Plan([1,3,7]) P /// Plan discret de vecteur normal v=(1, 3, 7), d'épaisseur omega=11 et d'intercept h=0.Bounding Box: ((0, 0, 0), (11, 11, 11)) }}} {{{id=15| P.list() /// [(0, 0, 1), (0, 1, 0), (0, 1, 1), (0, 2, 0), (0, 3, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1), (1, 2, 0), (1, 3, 0), (2, 0, 0), (2, 0, 1), (2, 1, 0), (2, 2, 0), (2, 3, 0), (3, 0, 0), (3, 0, 1), (3, 1, 0), (3, 2, 0), (4, 0, 0), (4, 0, 1), (4, 1, 0), (4, 2, 0), (5, 0, 0), (5, 1, 0), (5, 2, 0), (6, 0, 0), (6, 1, 0), (7, 0, 0), (7, 1, 0), (8, 0, 0), (8, 1, 0), (9, 0, 0), (10, 0, 0)] }}} {{{id=16| P.show3d() /// }}} {{{id=17| P = Plan([1,3,5], omega=7, h=20) P.show3d() /// }}}

Discrete 3d lines

Discrete 3d lines defined by cylinder offset:

{{{id=18| d = DroiteDiscrete3d_cylinder_offset((1,2,4), offset=1) d.bounding_box(((0,0,0),(6,6,6))) d /// Droite 3d defined by cylinder offset=1 and direction v=(1, 2, 4).Bounding Box: ((0, 0, 0), (6, 6, 6)) }}} {{{id=19| d.show3d() /// }}} {{{id=20| d.tikz() /// }}}

Reveillès Discrete 3d lines:

{{{id=21| d = DroiteDiscrete3d_reveilles((12,13,19)) d /// Droite 3d de Reveilles v=(12, 13, 19).Bounding Box: [(0, 0, 0), (20, 20, 20)] }}} {{{id=22| (0,0,0) in d /// True }}} {{{id=23| d.show3d() /// }}}

Comparing discrete planes

Let's now compare the Reveillès and Toutant 3D discrete lines:

{{{id=24| d = DroiteDiscrete3d_reveilles((10,20,29)) t = DroiteDiscrete3d_toutant((10,20,29)) d == t /// True }}}

The following example shows that Reveillès and Toutant are different for the vector (1,2,4) and that Toutant points are nearer from the line:

{{{id=25| d = DroiteDiscrete3d_reveilles((1,2,4)) t = DroiteDiscrete3d_toutant((1,2,4)) d == t /// False }}} {{{id=26| d.list() /// [(0, 0, 0), (0, 1, 1), (0, 1, 2), (1, 2, 3), (1, 2, 4)] }}} {{{id=27| t.list() /// [(0, 0, 0), (0, 0, 1), (0, 1, 2), (1, 2, 3), (1, 2, 4)] }}} {{{id=28| d.distance((0,1,1)) /// sqrt(2/7) }}} {{{id=29| d.distance((0,0,1)) /// sqrt(5/21) }}}

Intersection of planes

Intersection of two planes:

{{{id=30| p = Plan([1,-3,7],h=20) q = Plan([3,3,-5],h=14) i = p.intersection(q) i /// Intersection des objets suivants :Plan discret de vecteur normal v=(1, 3, 7), d'épaisseur omega=11 et d'intercept h=20.Bounding Box: ((0, 0, 0), (31, 31, 31))Plan discret de vecteur normal v=(3, 3, 5), d'épaisseur omega=11 et d'intercept h=14.Bounding Box: ((0, 0, 0), (25, 25, 25))Bounding Box: ((0, 0, 0), (25, 25, 25)) }}} {{{id=31| i.bounding_box(((-25,-25,-25),(25,25,25))) /// }}} {{{id=32| i.show3d() /// }}}

Rauzy fractals

Construction by projection

(This is will be in version 4.7 of Sage.)

The Rauzy fractal:

{{{id=33| s = WordMorphism('1->12,2->13,3->1') D = s.fixed_point('1') v = s.pisot_eigenvector_right() P = WordPaths('123',[(1,0,0),(0,1,0),(0,0,1)]) w = P(D[:200]) w.plot_projection(v) # optional long time (2 s) /// }}}

The 3d-Rauzy fractal:

{{{id=34| s = WordMorphism('1->12,2->13,3->14,4->1') D = s.fixed_point('1') v = s.pisot_eigenvector_right() P = WordPaths('1234',[(1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)]) w = P(D[:200]) w.plot_projection(v) # optional long time (1 s) /// }}}

Construction by dual morphisms

(This is in Sage since version 4.6.1.)

{{{id=35| from sage.combinat.e_one_star import E1Star, Patch, Face sigma = WordMorphism({1:[1,2], 2:[1,3], 3:[1]}) E = E1Star(sigma) P = Patch([Face((0,0,0),t) for t in [1,2,3]]) P.plot() /// }}} {{{id=36| image = E(P, iterations=12) image.plot() /// }}} {{{id=37| image.plot3d() /// }}}