kill(all)$

maxima :combination parametric draw3d,version 1.0
peter.vlasschaert@gmail.com,20/04/2021

ref :https://petervlaschemeng.weebly.com/
========================================
maxima :combination parametric plot 3d,version 1.0
peter.vlasschaert@gmail.com,19/04/2021
========================================

load packages,option
=================

load(lrats)$ ratprint:false $
load(draw)$

    draw3d
++++++++++

impulses
=======

wxdraw3d(
  zrange =[0,10],  
  points_joined = impulses,
  line_width    = 2,
  color         = "light-blue",
  xyplane       = 0,
  points(makelist([random(10.0),random(10.0),random(10.0)-5],k,0,25)) 
)$

f:makelist([random(10.0),random(10.0),random(10.0)-5],k,0,25);

length(f);

3D:  given:[-2,-2,3*u], u=0 → 1

wxdraw3d(
  zrange =[0,1],  
  xrange =[-2,2],
  yrange =[-2,2],    
  points_joined = impulses,
  line_width    = 2,
  color         = "light-blue",
  xyplane       = 0,
  points(makelist([-2,-2,3*u],u,0,1)) 
)$

3D plane
=======

3D:  given:[-2+4*u,-2+4*v,1], u=-2 →2, v=--3->3
-------------------------------------------------------------------

l:[];

for u:-2 thru 2 do(
   for v:-3 thru 3 do(
l:endcons([-2+4*u,-2+4*v],l)    
                     )                         
)$

→ x and y : values

l;

ll:length(l);

l[1][1];
l[1][2];

→ z :values

l2:makelist(1,i,1,35);

wxdraw3d(title = "plane @ z=1",         
         grid = true,
         xu_grid        = 5,
         yv_grid        = 7, 
         xlabel = "u",
         ylabel = "v",            
         surface_hide   = true,
          parametric_surface(u,
                             v,
                             1,
                           u, -2, 2, v, -3, 3) )$

u=-2 → 2 =>  2-(-2)+1 =5
v=-3 → 3 =>  3-(-3)+1 =7

3D line
======

3D:  given:[-2+4*u,-2+4*u,0], u=0→1 ( horizontal line @ z=0)
--------------------------------------------------

wxdraw3d(    xyplane =0, 
             color = royalblue,
             parametric(-2+4*u,-2+4*u,0,u,0,1))$
             

general plane 3D:[4*u-2,4*v-2,-3*v+7*u-+/-10], u=-3 →3,  v=-3 →3  
================================================ 

wxdraw3d(title = "general plane,u,v,-/+10+7*u-3*v",
         /* xyplane = 5, */        
         grid = true,
         xu_grid        = 7,
         yv_grid        = 7, 
         xlabel = "u",
         ylabel = "v",            
         surface_hide   = true,
         color = "red",
          parametric_surface(u,
                             v,
                             -3*v+7*u-10,
                           u, -3, 3, v, -3, 3),
          color = "blue",
          parametric_surface(u,
                             v,
                             -3*v+7*u+10,
                            u, -3, 3, v, -3, 3)
     )$

rem :red plane (lower plane) // blue plane (higher plane)

change : point red plane 3D (parametric : representation)

x0:-3;
y0:-3;
z0:-10;

wxdraw3d(title = "general plane,u,v,-/+10+7*u-3*v",
         /* xyplane = 5, */        
         grid = true,
         xu_grid        = 7,
         yv_grid        = 7, 
         xlabel = "u",
         ylabel = "v",            
         surface_hide   = true,
         color = "red",
          parametric_surface(u+x0,
                             v+y0,
                             -3*v+7*u+z0,
                             u, -3, 3, v, -3, 3)
          
       )$

point : iniitial  (-6,-6,-3*(-3)+7*(-3)-10) =(-6,-6,9-21-10)=(-6,-6,-22)

How construct this when  i = 1,2,3,4   (z =0 to 3)
------------------------------------------------------------------

wxdraw3d(
         title = "******",
         nticks = 60,
         line_width = 3,
         color =red,
         xyplane =0,
         proportional_axes=xy,         
         key = "vertical line",
         parametric(i,i,3*u,u,0,1)
        )$

m1:makelist([i,i,0],i,1,4);

m2:makelist([i,i,3],i,1,4);

wxdraw3d(         
         grid = true,         
         nticks = 60,
         line_width = 3,
         color = red,
         xyplane =0,
         xlabel = "x",
         ylabel = "y",
         zlabel = "z",
         /*proportional_axes=xy,*/         
         key = "points xy plane",
         points(m1),
         color = blue,
         key = "points xyz",
         points(m2),
         title = "vertical lines"
        )$

use:points_joined = impulses

wxdraw3d(
         title = "vertical lines",
         grid = true,         
         nticks = 60,
         line_width = 3,
         color = red,
         xyplane =0,
         xlabel = "x",
         ylabel = "y",
         zlabel = "z",
         points_joined = impulses,
         /*proportional_axes=xy,*/         
         points(m1),
         color = blue,
         points(m2)         
        )$

what when z value not fixed.  z = f(x,y)
---------------------------------------------------

3d point (x,y,f(x,y)) , example  : z =x^2+y^2

m3:[]; /* empty list */

for x:-3 thru 3 do(
 for y:-3 thru 3 do(
  m3:endcons([x,y,x^2+y^2],m3)  
    )
)$

m3;

wxdraw3d(
         title = "vertical lines & z = x^2+y^2",
         grid = true,         
         nticks = 60,
         line_width = 3,
         color = red,
         xyplane =0,
         xlabel = "x",
         ylabel = "y",
         zlabel = "z",
         points_joined = impulses,
         /*proportional_axes=xy,*/
         key = "vertical lines :red",         
         points(m3),     
         key = "paraboloid: z=x^2+y^2",
         enhanced3d = true,
         explicit(x^2+y^2,x,-3.1,3.1,y,-3.1,3.1),    
         title = "vertical lines"
        )$

rem : How to draw general equations of a line ( between : two 3D points)
----------------------------------------------------------------------------------------------------

1e) lines & vectors : 2D , label on  the graph
-------------------------------------------------------------

→ draw 2d vectors

 wxdraw2d(   xrange      = [0,12],
             yrange      = [0,10],                
             head_length = 1,
             /*unit_vectors = true,*/
             vector([0,1],[5,5]), /* default type */
             head_type = 'empty,
             vector([3,1],[5,5]),
             color = "green",             
             vector([6,1],[5,5]))$

→ draw 2d lines : explicit

wxdraw2d(    color = red,
             point_size = 9,
             xtics = 1,
             ytics = false,
             line_type = dots,             
             explicit(1 + x,x,-1,1),
             color = blue,
             line_width = 5,
             line_type = solid, /* default */
             explicit(2 + x,x,-1,1))$

→ draw 2d lines : points

m5:[[5,5],[7,7],[8,9]];

m6:[m5,[[2,2],[3,3],[5,5]]];

wxdraw2d(xrange     = [0,10],
             yrange     = [0,10],
             point_size = 20,
             points_joined = true,
             points(m5),
             color      = navy,
             label(["Horizontal orientation (default)",5,2]),
             label_orientation = 'vertical,
             color             = "#654321",
             label(["Vertical orientation",1,5]),
             color = "red",
             point_size =0.1,
             makelist( points(m6[i]),i,1,2)
             
)$

2e) lines & vectors : 3D , label on  the graph
-------------------------------------------------------------

→ draw 3d vectors

wxdraw3d(    xrange      = [0,12],
             yrange      = [0,10], 
             zrange      = [0,10],
             grid = true,               
             head_length = 1,
             xlabel = "x",
             ylabel = "y",
             zlabel = "z",
             title = "vectors 3D",
             xyplane = 0,
             vector([0,1,0],[5,5,0]), /* default type */
             label(["vector ",5+2,5+2,0]),
             head_type = 'empty,
             vector([3,1,2],[5,5,5]), 
             color = "red",            
             vector([6,1,8],[5,5,7]))$

→ draw 3d lines : explicit => parametric

q:[2*t+1,2*t+1,-t+2];
q11:subst([t=-1.0],q);

wxdraw3d(
   title = "draw 3d line,parametric (t)",
   line_width=3,
   /*axis_3d = false, */   
   xyplane = 0,
    xrange      = [-3,3],
    yrange      = [-3,3], 
    zrange      = [-3,3],
    xlabel = "x",
    ylabel = "y",
    zlabel = "z",
   color = "red" ,
   zaxis = false,    
   label(["line ",q11[1]+0.5,q11[2]+0.5,q11[3]]), 
   parametric(q[1],q[2],q[3],t,-1,1),
   zaxis_color = blue 
);

some :error parameters,wxdraw3d

→ draw 3d lines : points

m5a:[[5,5,2],[7,7,3],[8,9,4]];
m6a:[m5a,[[2,2,5],[3,3,0],[5,5,8]]];

wxdraw3d(xrange     = [0,10],
             yrange     = [0,10],
             point_size = 20,
             points_joined = true,
             points(m5a),
             color      = navy,
             label(["Horizontal orientation (default)",5,2,3]),
             label_orientation = 'vertical,
             color             = "#654321",
             label(["Vertical orientation",1,5,2]),
             color = "red",
             point_size =0.1,
             makelist( points(m6a[i]),i,1,2)
             
)$

?  How to draw polygons  'simple examples : triangles'
=========================================

→ draw

 scene1: gr2d(title="Ellipse",
                   nticks=30,
                   parametric(2*cos(t),5*sin(t),t,0,2*%pi))$
 scene2: gr2d(title="Triangle",color =green,fill_color = blue,
                   polygon([4,5,7],[6,4,2]))$
 wxdraw(scene1, scene2, columns = 2)$

→ draw2d

wxdraw2d(    color = brown,
             axis_left = false,
             axis_right = false,
             axis_bottom = false,
             axis_top = false,
             line_width  = 8,
             grid = true,
             polygon([[3,2],[7,2],[5,5]]),
             border      = false,
             fill_color  = green,
             polygon([[5,2],[9,2],[7,5]]),
             title = "draw2d ,color triangles"
     )$

rectangle([x1, y1], [x2, y2])
quadrilateral([x1, y1], [x2, y2], [x3, y3], [x4, y4])
triangle([x1, y1], [x2, y2], [x3, y3]) 

→ draw3d ( polygon (2D) → mesh)

Graphic object: polygon ([[x1, y1], [x2, y2], …])
Graphic object: polygon ([x1, x2, …], [y1, y2, …])∫

 wxdraw3d(
        line_width = 2,
        xyplane = 0,
        xlabel = "x",
        ylabel = "y",
        zlabel = "z",
        mesh([[1,0,0],[0,1,0]],
             [[0,0,1],[0,0,1]]))$

 wxdraw3d(
        title ="Two quadrilaterals",
        surface_hide = true,
        axis_3d = false,
        xyplane =0,
        line_width   = 3,
        color = red,
        key = "red quadrilateral",
        mesh([[0,0,0], [0,1,0]],
             [[2,0,2], [2,2,2]]),
        color = blue,
        key = "blue quadrilateral",
        mesh([[0,0,2], [0,1,2]],
             [[2,0,4], [2,2,4]])) $