# Grafika v 3D

## Základní volby, ovlivňující vzhled 3D grafiky

wxplot3d(cos(x*y),[x,-3,3], [y,-3,3]);

wxplot3d(sqrt(1-x^2-y^2),[x,-1,1],[y,-1,1]);

f(x,y):=cos(x*y)$

plot3d(f(x,y), [x,-3,3], [y,-3,3], ['grid,49,49],[box,false],[legend,false],[plot_format, openmath]);

load(draw)$

wxdraw3d(surface_hide=true, explicit(f(x,y),x,-3,3,y,-3,3));

wxdraw3d(surface_hide=true, enhanced3d=true, explicit(f(x,y),x,-3,3,y,-3,3));

wxdraw3d(surface_hide=true, enhanced3d=true, colorbox=false, 
explicit(f(x,y),x,-3,3,y,-3,3));

wxdraw3d (user_preamble  = "set pm3d at s depthorder",
        color          = green,
        explicit(f(x,y), x,-3,3,y,-3,3)) $

wxdraw3d(zrange=[0,20], 
xu_grid=25, yv_grid=25,explicit(1/(x^2+y^2), x,-1,1, y,-1,1));

f1(x,y):=(x^2*y)/(x^2+y^2);

wxplot3d(f1(x,y), [x,-3,3], [y,-3,3]);

## Speciální obrázky v 3D

Křivka daná parametricky

wxdraw3d(nticks=60, line_width=3, color=blue, 
parametric(cos(5*u)^2,sin(7*u),u-2,u,0,2)) $

wxdraw3d(nticks=400, line_width=2, color=red,
parametric(t*cos(2*%pi*t), t*sin(2*%pi*t), 2+t,t,0,10))$

wxdraw3d(nticks=400, line_width=2, color=red,
parametric(t*cos(2*%pi*t), t*sin(2*%pi*t), 2+t,t,0,10),
parametric(2+t, t*cos(2*%pi*t), t*sin(2*%pi*t),t,0,10),
parametric(t*cos(2*%pi*t), 2+t, t*sin(2*%pi*t),t,0,10))$

Plocha daná parametricky

wxdraw3d(xu_grid      = 50,
       yv_grid      = 15,
       surface_hide = true,
         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) )$

wxdraw3d(xu_grid      = 15,
       yv_grid      = 45,
       enhanced3d   = true,
       surface_hide = true,
         parametric_surface(r*cos(phi), r*sin(phi), phi, r,0,1,phi,0,6*%pi) )$

wxdraw3d(surface_hide = true,
color = "midnight-blue",proportional_axes=xyz,
 axis_3d      = false,
 xtics        = none,
 ytics        = none,
 ztics        = none,
spherical(1,theta,0,2*%pi,phi,0,%pi))$

wxdraw3d(surface_hide = true,proportional_axes=xy,
color = "midnight-blue",
 axis_3d      = false,
 xtics        = none,
 ytics        = none,
 ztics        = none,
cylindrical(1/2,z,-2,2,theta,0,2*%pi))$

wxdraw3d(surface_hide = true,
color = "blue",proportional_axes=xyz,
 axis_3d      = false,
 xtics        = none,
 ytics        = none,
 ztics        = none,
spherical(1,theta,0,2*%pi,phi,0,%pi),
color=red,
cylindrical(1/2,z,-2,2,theta,0,2*%pi))$

wxdraw3d(color = blue,
         explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3),
       yv_grid = 10,
       color   = red,
         explicit(x+y,x,-5,5,y,-5,5),
       surface_hide = true);

f(x,y):=x^2+y^2-4;

wxdraw3d(surface_hide = true,
       xlabel       = "x",
       ylabel       = "y",
       zlabel       = "z",
      
       color   = coral,
       xu_grid = 20,
       yv_grid = 10,
         explicit(x^2+y^2-4,x,-1.2,1.2,y,-1.2,1.2),
       color      = black,
       line_width = 2,
       nticks     = 40,
            parametric(cos(t),sin(t),f(cos(t), sin(t)),t,0,2*%pi) );

wxdraw3d(surface_hide = true,
       xlabel       = "x",
       ylabel       = "y",
       zlabel       = "z",
      
       color   = coral,
       xu_grid = 20,
       yv_grid = 10,
         explicit(x^2+y^2-4,x,-1.2,1.2,y,-1.2,1.2),
       color      = black,
       line_width = 3,
       nticks     = 40,
            parametric(cos(t),sin(t),(f(cos(t), sin(t))+0.1),t,0,2*%pi) );

U:log(sqrt((x+1)^2+y^2)) + log(sqrt((x-1)^2+y^2)) + log(sqrt((y+1)^2+x^2)) + log(sqrt((y-1)^2+x^2))$

U;

wxdraw3d(xu_grid=50,
       yv_grid=50,
explicit(U,x,-3/2,3/2,y,-3/2,3/2),
       contour_levels = 30,
       contour        = map,
       surface_hide   = true) ;

wxdraw3d(color = green,
         explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
       contour_levels = 15,
       contour        = both,
       surface_hide   = true) ;

wxdraw3d(
  surface_hide = true,
  color        = green,
  explicit(exp(-x^2-y^2),x,-2,2,y,-2,2),
  contour        = surface,
  contour_levels = 3);

wxdraw3d(enhanced3d   = true,
       implicit(x^3 + y^3 + z^3 + 1 = (x + y +z+1)^3,x,-2,2,y,-2,2,z,-2,2),
       surface_hide = true)$

## Animace

for d:1 thru 2 step 0.1 do
  plot2d(sin(x*d),[x,-10,10]);

with_slider(
d,makelist(i,i,10,20)/10,
[sin(x*d)],[x,-10,10],[y,-1,1]);

for d:1 thru 2 step 0.1 do
  draw2d(explicit(sin(x*d),x,-10,10));

with_slider_draw(
d,makelist(i,i,10,20)/10,
explicit(sin(d*x),x,-10,10)
);

for d:1 thru 2 step 0.1 do
  draw3d(enhanced3d   = true,explicit(cos(x*d)*sin(y*d),x,-%pi,%pi,y,-%pi,%pi));

Vytvoření animovaného gifu na Linuxu

Vytvoří jednotlivé PNG soubory

for k:1 thru 10 do
  draw2d(terminal   = png,
         file_name  = concat("ga",add_zeroes(k)),
         pic_width  = 300,
         pic_height = 300,
         explicit(x^(0.1*k),x,0,1));

Pomocí systémové příkazu convert je pak spojíme dohromady a vytvoříme animovaný gif.

system("convert -delay 10 ga*.png gifanim.gif")$

## Geometrické obrazce

wxdraw2d(fill_color = "sea-green",
       color      = aquamarine,  
       line_width = 6,
           polygon([[1,1],[3,0],[4,5],[0,3]]),

       transparent = true,
       line_type   = dots,
       color       = "dark-yellow",
           polygon([4,5,7],[6,4,2]),

       line_type   = solid,
       transparent = false,
       fill_color  = violet,
           rectangle([-2,-2],[8,-1]),   /* protilehle vrcholy */

       transparent = true,
       color       = "dark-goldenrod",
       line_width  = 1,
           rectangle([9,4],[2,-1.5]),

       transparent = false,
       fill_color  = grey80,
       line_width  = 2,
           ellipse(0,6,3,2,270,-270), 

       transparent = true,
       color       = "NaVy",  
       line_width  = 3,
           ellipse(7,6,2,3,30,-90),

       xrange      = [-3,10],
       yrange      = [-3,9] )$