load(draw)$

## Algunas funciones de dos variables f:R²→R

### Funciones explícitas y paramétricas

draw3d (
enhanced3d = true,
color = green,
cbrange = [-4,10],
explicit(x^2+y^2, x,-2,2,y,-2,2));

draw3d(color = blue,enhanced3d = false,
color = blue, xu_grid = 100, proportional_axes = xy,
yv_grid = 100,
cbrange = [0,2],
explicit(sqrt(1-x^2-y^2),x,-1,1,y,-1,1),surface_hide = true,transparent=true) $

%/* ESTE ES EL BUENO */;

file_search_maxima : cons(sconcat("/home/renato/###.{lisp,mac,mc}"), file_search_maxima)$

draw3d(view = [111, 40], xu_grid = 200,axis_3d = false, xtics=false,ytics=false,ztics=false,proportional_axes = xyz,
parametric_surface(sin(x)*cos(t),sin(x)*sin(t),cos(x),t,0,2*%pi,x,0,%pi/2),
color = green, enhanced3d = false, xu_grid = 100,
explicit(-(x-sqrt(2)/2)-(y-1/2)+1/2,x,0,1.2,y,0,1.2),
head_length = 0.1,head_angle = 15,color = black,
vector([sqrt(2)/2,1/2,1/2],[sqrt(2)/2,1/2,1/2]) 
)$

draw3d(font = "Arial",
font_size = 24,view = [78, 167], xu_grid = 100,axis_3d = true, proportional_axes = xyz, xlabel="x",ylabel="y",zlabel="z",
xtics={0,3},ytics={-3,0,3},ztics={-3,0,3},
parametric_surface(3*sin(x)*cos(t),3*sin(x)*sin(t),3*cos(x),t,-%pi/2,%pi/2,x,0,%pi))$

draw3d (
enhanced3d = true,
cbrange = [-4,10],
explicit(sqrt(1-x^2-y^2), x,-2,2,y,-2,2));

draw3d(color = blue,enhanced3d = false,
color = blue, xu_grid = 50, proportional_axes = xy,
yv_grid = 100,
cbrange = [0,2],
explicit(sqrt(1-x^2-y^2),x,-1,1,y,-1,1),surface_hide = true,transparent=true) $

draw3d(color = blue,enhanced3d = false,
color = blue, xu_grid = 50, proportional_axes = xy,
yv_grid = 100,
cbrange = [0,2],
explicit((x^+2*y^2-3)^2,x,-1.5,1.5,y,-1.5,1.5),surface_hide = true,transparent=true) $

draw3d(color = blue,enhanced3d = true,
color = blue, xu_grid = 50, proportional_axes = xy,
yv_grid = 25,
cbrange = [0,2],
explicit((x^2-y^2),x,-1.5,1.5,y,-1.5,1.5),surface_hide = true,transparent=true) $

kill(all);

draw3d(color = blue,enhanced3d = false,
color = blue, xu_grid = 50, proportional_axes = xy,
yv_grid = 25,
cbrange = [0,2],
explicit((x^2/10+y^2),x,-10,10,y,-10,10),surface_hide = true,transparent=true) $

### Paramétricas

x1:sqrt(u)*cos(v);
y1:sqrt(u)*sin(v);
z:x1*x1-y1*y1;
plot3d([x1,y1,z],[u,0,2], [v,-%pi,%pi],[grid,15,30],
  [xlabel,""],[ylabel,""],[legend,false],
  [box,false],[elevation,60],[azimuth,23],
  [palette,get_plot_option(palette,5)],[grid,40,40], [elevation, 100],
[azimuth, 117]);

x1:sqrt(u)*cos(v);
y1:sqrt(u)*sin(v);
z:sqrt(1-x1*x1-y1*y1);
plot3d([x1,y1,z],[u,0,1], [v,-%pi,%pi],[grid,15,30],
  [xlabel,""],[ylabel,""],[legend,false],
  [box,false],[elevation,60],[azimuth,23],
  [palette,get_plot_option(palette,5)],[grid,40,40], [elevation, 239],
[azimuth, 117]);

x1:sqrt(u)*cos(v);
y1:sqrt(u)*sin(v);
z1:-sqrt(1-x1*x1-y1*y1);
plot3d([x1,y1,z],[u,0,1], [v,-%pi,%pi],[grid,15,30],
  [xlabel,""],[ylabel,""],[legend,false],
  [box,false],[elevation,60],[azimuth,23],
  [palette,get_plot_option(palette,5)],[grid,40,40], [elevation, 232],
[azimuth, 109]);

x1:sqrt(u)*cos(v);
y1:sqrt(u)*sin(v);
z:u;
plot3d([x1,y1,z],[u,0,1], [v,-%pi,%pi],[grid,15,30],
  [xlabel,"x"],[ylabel,"y"],[legend,false],
  [box,true],[elevation,60],[azimuth,23],
  [palette,get_plot_option(palette,3)]);

x1:cos(u)*cos(v);
y1:cos(u)*sin(v);proportional_axes = xy,
z:sin(u);
plot3d([x1,y1,z],[u,0,%pi], [v,-%pi,%pi],[grid,15,30],
  [xlabel,"x"],[ylabel,"y"],[legend,false],
  [box,true],[elevation,60],[azimuth,23],
  [palette,get_plot_option(palette,3)]);

### Miscelánea

kill(all);

draw3d(color = blue,enhanced3d = false,
color = blue, xu_grid = 50, proportional_axes = xy,
yv_grid = 25,
cbrange = [0,2],
explicit((x^4+y^4-2*x^2),x,-10,10,y,-10,10),surface_hide = true,transparent=true) $

x1:sqrt(u)*cos(v);
y1:sqrt(u)*sin(v);
z:x1*x1+y1*y1-x1-y1+1;
plot3d([x1,y1,z],[u,0,2], [v,-%pi,%pi],[grid,15,30],
  [xlabel,""],[ylabel,""],[legend,false],
    [palette,get_plot_option(palette,5)],[grid,40,40], [elevation, 232],
[azimuth, 109]);

draw3d(point_type = filled_circle ,
point_size = 3, points([[1/2,1/2,1/2],[sqrt(2)/2,sqrt(2)/2,2-sqrt(2)],[-sqrt(2)/2,-sqrt(2)/2,3]]));

load(draw);

draw3d( font = "Arial", font_size = 20,
xu_grid = 50,
yv_grid = 25,enhanced3d = false,
view = [96,45],xtics=1/2,ytics=1/2,ztics=1,
surface_hide = true, color= red,
point_type = filled_circle ,
point_size = 1.5, points([[sqrt(2)/2,sqrt(2)/2,2-sqrt(2)],[-sqrt(2)/2,-sqrt(2)/2,2+sqrt(2)]]),
color= black,  points([[1/2,1/2,1/2]]), color=blue,
parametric_surface(  cos(u)*cos(v)   ,  sin(u)*cos(v) , cos(v)^2 - cos(u)*cos(v)-sin(u)*cos(v)+1, 
u, 0, 13*%pi, v, -%pi, %pi) )$

draw3d( font = "Arial", font_size = 20,
xu_grid = 50,
yv_grid = 25,enhanced3d = false,
view = [100,50],xtics=1/2,ytics=1/2,ztics=1,
surface_hide = true, color= red,
point_type = filled_circle ,
point_size = 2, points([[sqrt(2)/2,sqrt(2)/2,2-sqrt(2)],[-sqrt(2)/2,-sqrt(2)/2,2+sqrt(2)]]),
color= black,  points([[1/2,1/2,1/2]]), color=blue,
parametric_surface(  cos(u)*cos(v)   ,  sin(u)*cos(v) , cos(v)^2 - cos(u)*cos(v)-sin(u)*cos(v)+1, 
u, 0, 13*%pi, v, -%pi, %pi) )$

draw3d(explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
contour_levels = 15,
contour = both,
surface_hide = true) $

draw3d(xu_grid = 400, yv_grid = 300,  axis_3d = false, xtics=false,ytics=false,ztics=false,
       points_joined = true, ip_grid=[100,100],ip_grid_in=[10,10], x_voxel = 25, y_voxel = 25, z_voxel= 25,
color=black, proportional_axes = xyz,  color=black,  line_width = 3,  parametric(t,0,0,t,-3.75,8),
point_type = filled_circle , point_size = 1.2, color=blue,points([[7,0,0]]),  colorbox = false,
enhanced3d=true, implicit(x^2/2+y^2+z^2=5, x,-4,4,y,-4,4,z,-4,4));

## Dibujando superficies segundo orden

terminal = screen;

/* draw3d (implicit): non defined variable se resolvió escribiendo, terminal = screen, */
draw3d(
         enhanced3d = [x-y,x,y,z],
         implicit((x^2+y^2+z^2-1)*(x^2+(y-1.5)^2+z^2-0.5)=0.015,
                  x,-1,1,y,-1.2,2.3,z,-1,1)) $

load(draw);

draw3d( enhanced3d = true, implicit((x^2+y^2+z^2-1)=0.0,x,-1,1,y,-1.2,2.3,z,-1,1)) $

draw3d( enhanced3d = true, x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2+y^2+z^2-1)=0.0,x,-1,1,y,-1.2,2.3,z,-1,1),colorbox=false, proportional_axes = xyz) $

/* Elipsoide */
draw3d( enhanced3d = true, x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2/16+y^2/9+z^2/4)=1.0,x,-4,4,y,-3,3,z,-3,3),
    colorbox=false, proportional_axes = xyz) $

/* Hipérboloide de dos hojas */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2-y^2-z^2)=1.0,x,-6,6,y,-6,6,z,-6,6),colorbox=false, proportional_axes = xyz) $

/* Cono elíptico */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2/4+y^2-z^2)=0.0,x,-12,12,y,-6,6,z,-6,6),colorbox=false, proportional_axes = xyz) $

draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2+y^2-z^2)=0.0,x,-4,4,y,-4,4,z,0,4),colorbox=false, proportional_axes = xyz) $

/* Paraboliode hiperbólico */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2/4-y^2-z)=0.0,x,-12,12,y,-6,6,z,-6,8),colorbox=false, proportional_axes = xyz) $

/* Paraboloide elíptico */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2/4+y^2-z)=0.0,x,-6,6,y,-4,4,z,-1,8),colorbox=false, proportional_axes = xyz) $

/* Cilindro parabólico */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2-2*y)=0.0,x,-6,6,y,-1,4,z,-1,8),colorbox=false, proportional_axes = xyz) $

/* Cilindro elíptico */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2/9+y^2/4-1)=0.0,x,-6,6,y,-4,4,z,-1,8),colorbox=false, proportional_axes = xyz) $

/* Cilindro hiperbólico */
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2/9-y^2/4-1)=0.0,x,-7,7,y,-4,4,z,-1,8),colorbox=false, proportional_axes = xyz) $

draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((4*x^2+4*y^2-z^2)=0.0,x,-5,5,y,-6,6,z,-6,6),colorbox=false, proportional_axes = xyz) $

/* OTROS */;

a:2;
draw3d( enhanced3d = true,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
    implicit((x^2+y^2-z^2)=-a^2,x,-6,6,y,-6,6,z,-6,6),colorbox=false, proportional_axes = xyz) $

a:1;
draw3d( enhanced3d = false,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
implicit((x^2+y^2-z^2)=-a^2,x,-1,1,y,-1,1,z,0,2),
implicit((4*x^2+4*y^2-z^2)=0.0,x,-1,1,y,-1,1,z,0,2),
colorbox=false, proportional_axes = xyz) $

a:1;
draw3d( enhanced3d = true,  x_voxel=10, y_voxel=10, z_voxel=10,palette = color,
implicit((x^2+y^2-z^2)=-a^2,x,-6,6,y,-6,6,z,-1,1),
implicit((4*x^2+4*y^2-z^2)=0.0,x,-8,8,y,-8,8,z,-1,1),
colorbox=false, proportional_axes = xyz) $

a:1;
draw3d(enhanced3d = false,  x_voxel=20, y_voxel=20, z_voxel=20,palette = color,
implicit((x^2+y^2-z^2)=-a^2,x,-8,8,y,-8,8,z,-2,2),
colorbox=false, proportional_axes = xyz) $

## Armónicos esféricos

??spherical_harmonic;

 spherical_harmonic (3, 0, x, y);

spherical_harmonic(2,-1, theta, phi)$
abs(%)^2;spherical_harmonic(2,0, theta, phi)$
abs(%)^2;spherical_harmonic(2,1, theta, phi)$
abs(%)^2;

wxplot3d (abs(spherical_harmonic(2,-2, theta, phi))^2 , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false],[legend,false],[grid, 50,50] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true],
[gnuplot_preamble,"set size ratio -1"] )$

for k:0 thru 2 do  wxplot3d (abs(spherical_harmonic(2,k, theta, phi))^2 , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false],[legend,false],[grid, 50,50] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true],
[gnuplot_preamble,"set size ratio -1"] )$

plot3d (abs(spherical_harmonic(2,2, theta, phi))^2  , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false], [legend,false],[grid, 100,75] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true],
[gnuplot_preamble,"set size ratio -1"],
[gnuplot_term, "png size 1500,1500"],[gnuplot_out_file, "spherical2.png"])$

spherical_harmonic(3,1, theta, phi);
abs(%)^2;
plot3d (% , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false], [legend,false],[grid, 100,75] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true],
[gnuplot_preamble,"set size ratio -1"],
[gnuplot_term, "png size 1500,1500"],[gnuplot_out_file, "spherical.png"])$

spherical_harmonic(2,0, theta, phi);
abs(%)^2;
plot3d (% , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false],[legend,false],[grid, 100,75] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true],
[gnuplot_preamble,"set size ratio -1"],
[gnuplot_term, "png size 1500,1500"],[gnuplot_out_file, "spherical.png"])$

spherical_harmonic(3,1, theta, phi);
realpart(%)^2;
plot3d (% , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false],[legend,false],[grid, 100,100] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true])$

spherical_harmonic(2,1, theta, phi);
imagpart(%)^2;
plot3d (% , 
 [theta, -%pi, 0],[phi, 0, 2*%pi], [box, false],[legend,false],[grid, 100,100] ,
 [transform_xy,spherical_to_xyz], [mesh_lines_color,true])$