Back to main page
Back to draw-VTKcontents

draw-VTK: 3D geometric objects

This section shows how to draw 3D objects with the Maxima-VTK interface.

Once you have opened a Maxima session, load package draw and then set global variable draw_renderer to vtk:

load("draw") $
draw_renderer : 'vtk $

A blue sphere. This object needs the following arguments: the radius, the center, the theta and phi resolutions, the start and end values for theta and phi, and the tesselation type. When the tesselation type is true, the surface is generated by rectangles, when false, by triangles.

draw3d(
  sphere(1,[0,2,0],30,30,0,360,0,180,true)) $

Transparent and opaque cones. Cones need the following arguments: height, radius, center, direction, resolution, and capping. See that colors can be specified in hexadecimal RGB code or in English words. Also, as the rest of solid objects, cones are affected by the opacity option.

draw3d(
  color   = "#abc80e",
  cone(1,1,[0,0,0],[0,2,1],30,false),
  color   = red,
  opacity = 1/3,  
  cone(1,1,[0,0,0],[0,-2,-1],30,false))$

Cylinder objects with different resolutions. Arguments for this object are: height, radius, center, resolution, and capping. This object needs further work to add the orientation argument.

draw3d(
   color = yellow,
   cylinder(15,1,[0,0,0],3,false),
   color = red,
   cylinder(8,3,[0,0,0],4,false),
   color = blue,
   cylinder(5,5,[0,0,0],40,false)  ) $

Cube objects with different dimensions. Arguments for this object are: length, width, height, and center. This object needs further work to add an orientation argument. (Cube is also the name used by VTK for this object, although another one would be better.)

draw3d(
   cube(3, 4, 5, [0, 0, 0]),
   color = orange,
   cube(1/2, 5, 3, [7, 0, 0]),
   opacity = 0.5,
   cube(5, 1/3, %pi, [5, 5, -4])) $

Family of available 3d objects. We make use here of two global options: with axis_3d = false axes box is removed and with dimensions = [300,300] we fix the window dimensions.

draw3d(
  axis_3d    = false, 
  dimensions = [300,300],

  color      = red,
  cone(1,1,[0,0,0],[0,2,1],30,true),
  color      = blue,
  cylinder(1,1,[0,0,2],30,false),
  color      = dark_yellow,
  cube(1,1,1,[0,0,4]),
  color      = light_gray,
  sphere(1,[0,2,0],30,30,0,360,0,180,true));

Regular polyhedra.

/* Defining vertices */
vp:float(
   [[0 ,0 ,2*%phi^2],
    [%phi^2 ,0 ,%phi^3],
    [%phi ,%phi^2 ,%phi^3],
    [0 ,%phi ,%phi^3],
    [-%phi ,%phi^2 ,%phi^3],
    [-%phi^2 ,0 ,%phi^3],
    [-%phi ,-%phi^2 ,%phi^3],
    [0 ,-%phi ,%phi^3],
    [%phi ,-%phi^2 ,%phi^3],
    [%phi^3 ,%phi ,%phi^2],
    [%phi^2 ,%phi^2 ,%phi^2],
    [0 ,%phi^3 ,%phi^2],
    [-%phi^2 ,%phi^2 ,%phi^2],
    [-%phi^3 ,%phi ,%phi^2],
    [-%phi^3 ,-%phi ,%phi^2],
    [-%phi^2 ,-%phi^2 ,%phi^2],
    [0 ,-%phi^3 ,%phi^2],
    [%phi^2 ,-%phi^2 ,%phi^2],
    [%phi^3 ,-%phi ,%phi^2],
    [%phi^3 ,0 ,%phi],
    [%phi^2 ,%phi^3 ,%phi],
    [-%phi^2 ,%phi^3 ,%phi],
    [-%phi^3 ,0 ,%phi],
    [-%phi^2 ,-%phi^3 ,%phi],
    [%phi^2 ,-%phi^3 ,%phi],
    [2*%phi^2 ,0 ,0],
    [%phi^3 ,%phi^2 ,0],
    [%phi ,%phi^3 ,0],
    [0 ,2*%phi^2 ,0],
    [-%phi ,%phi^3 ,0],
    [-%phi^3 ,%phi^2 ,0],
    [-2*%phi^2 ,0 ,0],
    [-%phi^3 ,-%phi^2 ,0],
    [-%phi ,-%phi^3 ,0],
    [0 ,-2*%phi^2 ,0],
    [%phi ,-%phi^3 ,0],
    [%phi^3 ,-%phi^2 ,0],
    [%phi^3 ,0 ,-%phi],
    [%phi^2 ,%phi^3 ,-%phi],
    [-%phi^2 ,%phi^3 ,-%phi],
    [-%phi^3 ,0 ,-%phi],
    [-%phi^2 ,-%phi^3 ,-%phi],
    [%phi^2 ,-%phi^3 ,-%phi],
    [%phi^3 ,%phi ,-%phi^2],
    [%phi^2 ,%phi^2 ,-%phi^2],
    [0 ,%phi^3 ,-%phi^2],
    [-%phi^2 ,%phi^2 ,-%phi^2],
    [-%phi^3 ,%phi ,-%phi^2],
    [-%phi^3 ,-%phi ,-%phi^2],
    [-%phi^2 ,-%phi^2 ,-%phi^2],
    [0 ,-%phi^3 ,-%phi^2],
    [%phi^2 ,-%phi^2 ,-%phi^2],
    [%phi^3 ,-%phi ,-%phi^2],
    [%phi^2 ,0 ,-%phi^3],
    [%phi ,%phi^2 ,-%phi^3],
    [0 ,%phi ,-%phi^3],
    [-%phi ,%phi^2 ,-%phi^3],
    [-%phi^2 ,0 ,-%phi^3],
    [-%phi ,-%phi^2 ,-%phi^3],
    [0 ,-%phi ,-%phi^3],
    [%phi ,-%phi^2 ,-%phi^3],
    [0 ,0 ,-2*%phi^2]])$

/* regular faces are built with triangles */
make_triangles([v]) :=  map(lambda([z], triangle(vp[z[1]], vp[z[2]], vp[z[3]])), v) $

/* TETRAHEDRON */
draw3d(
  color = yellow,
  axis_3d = false,
  opacity = 2/3, 
  make_triangles([ 4, 34, 47],[4, 38, 34],[4, 47, 38],[34, 38, 47])) $
/* CUBE */
draw3d(
  color = blue,
  axis_3d = false,
  background_color = green,
  make_triangles([ 4, 18, 38], [38, 28, 4], [ 4, 23, 18], [18, 23, 34],
                 [ 4, 28, 47], [ 4, 47, 23], [28, 38, 60], [28, 60, 47],
                 [23, 47, 34], [47, 60, 34], [38, 18, 60], [18, 34, 60])) 
/* OCTAHEDRON */
draw3d(
  make_triangles([ 7, 10, 43], [ 7, 22, 10], [ 7, 43, 49], [ 7, 49, 22],
                 [55, 10, 43], [55, 22, 10], [55, 43, 49], [55, 49, 22])) $
/* OCTAHEDRON AND ICOSAHEDRON */
/* you can drag and move each
   polyhedron independently   */
draw(
  dimensions = [500,250],
  columns = 2,
  gr3d(
    color = red,
    axis_3d = false,
    background_color = gray,
    make_triangles([ 4, 8, 11], [11, 8, 18], [11, 18, 20],
                   [ 4, 13, 23], [ 4, 23, 8], [ 8, 23, 16],
                   [ 4, 11, 28], [ 4, 28, 30], [ 4, 30, 13],
                   [ 8, 16, 34], [ 8, 34, 18], [18, 34, 36],
                   [11, 20, 28], [20, 45, 28], [20, 38, 45],
                   [13, 30, 23], [23, 30, 41], [41, 30, 47],
                   [16, 23, 34], [34, 23, 50], [50, 23, 41],
                   [18, 36, 52], [18, 52, 38], [18, 38, 20],
                   [28, 45, 56], [28, 56, 47], [28, 47, 30],
                   [34, 50, 60], [34, 60, 36], [36, 60, 52],
                   [38, 52, 60], [38, 60, 56], [38, 56, 45],
                   [41, 47, 56], [41, 56, 60], [41, 60, 50] )),
  gr3d(
    color = blue,
    axis_3d = false,
    background_color = green,
    make_triangles([ 2, 6, 17], [ 2, 12, 6], [ 2, 17, 37], [ 2, 37, 27],
                   [ 2, 27, 12], [37, 54, 27], [27, 54, 46], [27, 46, 12],
                   [12, 46, 31], [12, 31, 6], [ 6, 31, 33], [ 6, 33, 17],
                   [17, 33, 51], [17, 51, 37], [37, 51, 54], [58, 54, 51],
                   [58, 46, 54], [58, 31, 46], [58, 33, 31], [58, 51, 33] ))) $
/* INTERSECTING TETRAHEDRA */
draw3d(
  axis_3d = false,
  make_triangles([ 4, 34, 47],[4, 38, 34],[4, 47, 38],[34, 38, 47]),
  make_triangles([18, 23, 28], [18, 23, 60], [18, 28, 60], [23, 28, 60])) $

Back to main page
Back to draw-VTK contents


by Mario Rodríguez Riotorto