Parametric functions

This section shows how to draw parametric curves and surfaces with the draw package.

Parametric and explicit functions.

```draw2d(color = ReD,   /* case insensitive */
explicit(exp(x),x,-1,3),
color = "#0000Ff", /* blue, in doubled quoted hexadecimal */
key   = "This is the parametric one!!",
parametric(2*cos(rrr),rrr^2,rrr,0,2*%pi))\$
```

The Möbius band.

```draw3d(xu_grid      = 50,
yv_grid      = 15,
surface_hide = true,
terminal     = eps,
parametric_surface(cos(a)*(3+b*cos(a/2)),
sin(a)*(3+b*cos(a/2)),
b*sin(a/2), a,-%pi,%pi,b,-1,1) )\$
```

Sea shell.

```draw3d(title          = "Sea shell",
pic_width      = 300,  /* Since Maxima 5.23, pic_width and pic_height are deprecated. */
pic_height     = 600,  /* See option dimensions                                       */
terminal       = png,
xu_grid        = 100,
yv_grid        = 25,
rot_vertical   = 100,  /* Since Maxima 5.23, rot_vertical and rot_horizontal are deprecated */
rot_horizontal = 20,   /* See option view */
surface_hide   = true,
color          = blue,
parametric_surface(0.5*u*cos(u)*(cos(v)+1),
0.5*u*sin(u)*(cos(v)+1),
u*sin(v) - ((u+3)/8*%pi)^2 - 20,
u, 0, 13*%pi, v, -%pi, %pi) )\$
```

The torus and the sphere.

```draw3d(surface_hide = true,
pic_height   = 400,  /* Since Maxima 5.23, pic_width and pic_height are deprecated. */
pic_width    = 400,  /* See option dimensions.                                      */
terminal     = png,
title        = "Two parametric surfaces",
color = "dark-khaki",
parametric_surface((1-0.2*cos(v))*cos(u),
(1-0.2*cos(v))*sin(u),
0.2*sin(v), u,0,2*%pi,v,0,2*%pi),
color = "midnight-blue",
parametric_surface(cos(u)*cos(v),
cos(u)*sin(v),
1+sin(u), u,-2*%pi,2*%pi,v,0,2*%pi) )\$
```

An enhanced torus.

```draw3d(palette    = [7,-15,3],
enhanced3d = (1-0.2*cos(v))*sin(u),
parametric_surface(
(1-0.2*cos(v))*cos(u),
(1-0.2*cos(v))*sin(u),
0.2*sin(v),
u, 0, 2*%pi, v, 0, 2*%pi)) \$
```

Interlocking enhanced tori.

```draw3d(enhanced3d = sin(u)+cos(v),
terminal   = eps_color,
palette    = [8,4,3],
eps_height = 15,  /* Since Maxima 5.23, eps_width and eps_height are deprecated. */
eps_width  = 15,  /* You'll get the same effect with dimensions=100*[15,15]      */
parametric_surface(cos(u)+.5*cos(u)*cos(v),
sin(u)+.5*sin(u)*cos(v),
.5*sin(v),
u, -%pi, %pi,
v, -%pi, %pi),
parametric_surface(1+cos(u)+.5*cos(u)*cos(v),
.5*sin(v),
sin(u)+.5*sin(u)*cos(v),
u, -%pi, %pi,
v, -%pi, %pi)) \$
```

Enhanced 3d with wired surface.

```draw3d(
enhanced3d    = true,
wired_surface = true,
parametric_surface(sin(v), cos(v), u*v,u,0,3,v,0,3)) \$
```

Tubes can be plotted indicating a parametric curve and the radius. Graphic object tube works with Maxima 5.21 or newer.

```/* Sinusoidal tube with constant diameter */

draw3d(
surface_hide = true,
enhanced3d = true,
palette = gray,
xu_grid = 50,
tube(cos(a), a, 0, 1,
a, 0, 4*%pi) )\$
```
```/* Sinusoidal tube with varying diameter */

draw3d(
surface_hide = true,
enhanced3d = true,
palette = gray,
xu_grid = 50,
tube(cos(a), a, 0, cos(a/10)^2,
a, 0, 4*%pi) )\$
```
```/* We can select if we want open or closed extremes */

draw3d(
surface_hide = true,
tube_extremes = [open, closed],
tube(a, a, a^2, 1,
a, -2, 2) )\$
```
```/* A family of knots */

knot(m,n,h,p,q,t,k,i,r,s) :=
block([a],
gr3d(
xu_grid = 100,
enhanced3d = true,
colorbox = false,
tube(
m * cos(p*a) + n*cos(q*a) + k*cos(r*a),
m * sin(p*a) + n*sin(q*a) + k*sin(r*a),
h * sin(t*a) + i*sin(s*a),
0.1,
a, 0, 2*%pi)))\$

k1 : knot(1,1.5,0.35,1,-2,3,0,0,0,0) \$
k2 : knot(1,0.45,0.35,2,-3,5,0,0,0,0) \$
k3 : knot(1,0.45,0.35,3,-2,5,0,0,0,0) \$
k4 : knot(1,0.45,0.35,4,-1,5,0,0,0,0) \$

draw(
terminal = eps_color,
eps_width = 15,  /* Since Maxima 5.23, eps_width and eps_height are deprecated. */
eps_height = 15, /* You'll get the same effect with dimensions=100*[15,15]      */
columns = 2,
k1, k2, k3, k4 )\$
```

Archimedes would like this one. A cylinder circumscribed on a sphere.

```draw3d(terminal       = eps_color,
eps_width      = 8,  /* Since Maxima 5.23, eps_width and eps_height are deprecated. */
eps_height     = 8,  /* You'll get the same effect with dimensions=100*[8,8]      */
surface_hide   = true,
xtics          = none,
ytics          = none,
ztics          = none,
axis_3d        = false,
rot_vertical   = 48,  /* Since Maxima 5.23, rot_vertical and rot_horizontal are deprecated */
rot_horizontal = 22,  /* See option view */
color  = blue,
parametric_surface(cos(a)*cos(b),
cos(b)*sin(a),
sin(b), a,0,2*%pi,b,-%pi/2,%pi/2),
color          = cyan,
parametric_surface(1.01*cos(a),1.01*sin(a),z,a,0,3/2*%pi,z,-1,1),
xu_grid        = 25,
yv_grid        = 5,
parametric_surface(1.01*r*cos(a),1.01*r*sin(a),1,a,0,3/2*%pi,r,0,1),
parametric_surface(1.01*r*cos(a),1.01*r*sin(a),-1,a,0,3/2*%pi,r,0,1)  );
```

Parametric 3D curves can be rendered with a colored 4th dimension. This feature is a contribution by Joan Pau Beltran. It will be present in Maxima 5.19, or you can download the latest version from cvs.

```draw3d(
terminal   = wxt, /* Since Maxima 5.23, you need Gnuplot 4.4 to avoid errors */
color      = blue,
nticks     = 60,
line_width = 3,
enhanced3d = (u-1)^2,
parametric(cos(5*u)^2,sin(7*u),u-2,u,0,2)) \$
```

The Klein bottle.

```x1:6*cos(u)*(1+sin(u)) + 4*(1-0.5*cos(u))*cos(u)*cos(v) \$
x2:6*cos(u)*(1+sin(u)) - 4*(1-0.5*cos(u))*cos(v) \$
y1:16*sin(u)+4*(1-0.5*cos(u))*sin(u)*cos(v) \$
y2:16*sin(u) \$
z1:4*(1-0.5*cos(u))*sin(v) \$
x : if u<%pi then x1) else x2 \$
y : if u<%pi then y1 else y2 \$
z : z1;

draw3d(
enhanced3d=true,
parametric_surface(x,y,z,u,0,2*%pi,v,0,2*%pi) )\$
```

by Mario Rodríguez Riotorto