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 $

The sphere needs the center and the radius.

draw3d(
    color = red,
    sphere([0,2,0],1),
    color = green,
    sphere([0,2,2],1),
    color = blue,
    sphere([0,2,4],1) ) $

Transparent and opaque cones. Cones need the following arguments: center (midpoint of the height), radius, height, and direction. 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. As shown in this example, you can make use of the cap.

draw3d(
  capping = true,
  color   = "#abc80e",
  cone([0,0,0],0.5,3,[0,2,1]),
  color   = cyan,
  capping = false,
  opacity = 0.7,
  cone([0,0,0],1,1,[0,-2,-1]))$

Cylinders are defined by center (midpoint of its height), radius, height, and direction. The colored arrows indicate the positive directions of the axes. In this example both the cone and the cylinder point to a common random direction. By default, if the direction vector is [0,0,0], it is substituted by [0,0,1].

d: [random(2.0)-1,random(2.0)-1,random(2.0)-1]$

draw3d(
    head_length = 0.5,
    line_width  = 0.1,
    capping     = true,
    axis_3d     = false,
    
    /* x- axis */
    color = red,
    vector([-8,0,0],[16,0,0]),
    
    /* y- axis */
    color = green,
    vector([0,-8,0],[0,16,0]),
    
    /* z- axis */
    color = blue,
    vector([0,0,-8],[0,0,16]),
    
    color = white,
    cylinder([0,0,0],0.5,16,d),
    cone([0,0,0],3,5,d) ) $

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([0,0,0],1,1,[0,2,1]),
  color      = blue,
  cylinder([0,0,2],1,1,[0,0,1]),
  color      = dark_yellow,
  cube(1,1,1,[0,0,4]),
  color      = light_gray,
  sphere([0,2,0],1))$

Prisms are defined by the center (midpoint of its height), number of lateral faces, the coordinates of any point situated on a line containing a lateral edge, height, and direction.

draw3d(
    color   = gold,
    capping = true,
    prism([0,0,0],8,[1,0,0],2,[0,0,0]),
    color   = gray,
    capping = [true,false],
    prism([1,1,1],5,[1,3,2],2,[1,2,-6]) ) $

For a better understanding of the arguments, take a look at the following screenshot:

draw3d(
    head_length      = 0.5,
    line_width       = 0.1,
    axis_3d          = false,
    
    /* x- axis */
    color            = red,
    vector([-8,0,0],[16,0,0]),
    
    /* y- axis */
    color            = green,
    vector([0,-8,0],[0,16,0]),
    
    /* z- axis and direction vector */
    color            = blue,
    line_width       = 0.3,
    head_length      = 1,
    vector([0,0,0],[0,0,5]),
    
    /* the prism */
    color            = yellow,
    prism([0,0,0],8,[4,4,10],6,[0,0,5]),
    
    /* edge and edge point */
    point_type       = sphere,
    color            = white,
    points([[4,4,10]]),
    
    line_width       = 1,
    points_joined    = true,
    point_type       = dot,
    line_type        = dashes,
    color            = black,
    points([[4,4,13],[4,4,-13]]),

    /* labels and indicators */
    color            = red,
    font_size        = 1,
    point_type       = dot,
    line_width       = 1,
    line_type        = solid,
    
    label(["Center (0,0,0)", -5, -5, -8]),
    points([[0, -5, -8], [0, 0, 0]]),
    
    label(["Direction (0,0,5)", -5, -5, 5]),
    points([[0, -5, 5], [0, 0, 3]]),
    
    label(["Point on edge line: (4,4,10)", -5, -5, 10]),
    points([[5, -5, 10], [4, 4, 10]])  ) $

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