kill(all)$

How to construct : z=f(x,y), tangent plane,tangent line,version 1.0,part2
peter.vlasschaert@gmail.com, 21/03/2020.

ref :http://people.kzoo.edu/barth/math214/SurfacePlaneLine.html

load packages
===========

load(lrats)$

2d version  : y =f(x)  , part   1
3d version  : z=f(x,y), part   2 

cartesian : line 3d
=============
through the point (x0,y0,z0)
(x-x0)/a = (y-y0)/b = (z-z0)/c

p1a:(x-x0)/a = (y-y0)/b; 
p1b:(z-z0)/c = (y-y0)/b; 

{a,b,c} = rico in the direction {x,y,z}

cartesian : plane 3d
===============
trough the point (x0,y0,z0)

1e) plane 3d
---------------

p2a:A*x+B*y+C*z+D = 0;

2e) plane 3d :trough the point (x0,y0,z0)
-------------------------------------------------

p2b:subst([x=x0,y=y0,z=z0],p2a);

p2b1:solve(p2b,D);

p2b2:subst(p2b1,p2a);

p2b3:(-1)*(factorsum(lhs(p2b2)) = rhs(p2b2));

rem :[A,B,C] = normal to plane 'p2a'

function : z = f(x,y) = x^2+y^2
======================

p3a:z =f(x,y);
p3a1:z = x^2+y^2;

draw 1: draw surface z=f(x,y)
======================

p3a2:wxplot3d(rhs(p3a1),[x,-2,2],[y,-2,2]);

How to make computation : tangent plane. @ ' x=x0,y=y0 '
==============================
see : part 1, ' tangent line'

  => tangent line : 2d

p4:y-y0 = at(diff(f(x),x),x=x0)*(x-x0);

p4a:p4+y0;

p4b:subst([(at('diff(f(x),x,1),x=x0))=m],p4a);

  => tangent plane :3d,@ ' x=x0,y=y0 '

1e)  We need  two lines: to construct the tangent plane
------------------------------------------------------------------

first line : fixed  x=x0   , z = f(x0,y)
------------------------------------------
2d :  z = f(y)   ,use  'p4a,p4b'

p5a1:m1 = at(diff(f(x0,y),y),y=y0);

p5a2:[y=z,y0=z0,x=y,x0=y0,m=m1,p5a1];

p5a3:subst(p5a2,p4b);

p5a4:subst([z=z0,x=x0,y=y0],p3a);

p5a5:ev(subst([p5a4],p5a3),nouns);

construct :form 'cartesian : line 3d' , find {a,b,c}
use : p5a1,p5a3

p5a61:(z-z0)/m1 = (y-y0)/1;

p5a62: x=x0;

p5a63:[a,b,c] =subst([p5a1],[0,1,m1]);

p5a64:map("=",lhs(p5a63),rhs(p5a63));

rem :at('diff(f(x0,y),y,1),y=y0)]  = d(f(x0,y0))/dy

second line : fixed  y=y0   , z = f(x,y0)
------------------------------------------
2d :  z = f(x)   ,use  'p4a,p4b'

p6a1:m2 = at(diff(f(x,y0),x),x=x0);
p6a2:[y=z,y0=z0,y=x,y0=x0,m=m2,p6a1];
p6a3:psubst(p6a2,p4b);

rem : psubst , never used before this date  in any document.

? psubst;

p6a4:subst([p6a1],p6a3);

use :p5a4

p6a5:subst([p5a4],p6a4);

construct :form 'cartesian : line 3d' , find {a,b,c}
use : p6a1,p6a4

p6a61:(z-z0)/m2 = (x-x0)/1;
p6a62: y = y0;

p6a63:[a,b,c] =subst([p6a1],[1,0,m2]);

p6a64:map("=",lhs(p6a63),rhs(p6a63));

2e)  We need  plane: find :{A,B,C}, vector is normal to the plane.
-------------------------------------------------------------------------------
see : 'above': p2a, 
  =>   given:point (x0,y0,z0) in space, 'see above'  to find  z0
  =>    A*x+B*y+C*z+D = 0

a)  find : D
-------------

p7a1:p2b1;

b) find : {A,B,C}
--------------------
to find : D

solution : vector product of first line @ second line, 'Matrix computation'

 →  b1)  direction of  the lines, 'firstline @ secondline '.  ( = orientation in space of the line)
==================================================================

p7a2a:p5a63;
p7a2b:p6a63;

→  b2)  vector product, 'firstline @ secondline '.            ( =normal to the plane)
==========================================================
result :[A,B,C] ,=>  A → x component vector
                             B →y component vector
                             C →z component vector

rem : normal to the plane → normal line through the plane.(@ x=x0,y=y0,z=f(x,y)=z0)
rem : vector product  = cross product
rem :google search : prompt  vector product maxima

b2a) load packages
------------------------

load(vect)$

b2b) operator : ~ used maxima  (vector product :x)
--------------------------------------------------------------

p7b1:rhs(p7a2a);
p7b2:rhs(p7a2b);

p7b3:p7b1~p7b2;

result :[A,B,C]

p7b4:[A,B,C] = express(%);

p7b5:map("=",lhs(p7b4),rhs(p7b4));

p7b6:append(p7b5,p7a1);

3e) equation of plane ( = tangent plane)
-------------------------------------------------

1e) form :A*x+B*y+C*z+D = 0;
=======================

p7c1:subst(p7b6,p2a);

2e) form :C*(z0-z)+B*(y0-y)+A*(x0-x)=0
==============================

p7c2:subst(p7b6,p2b3);

special topic ( = normal line)
=====================
{a,b,c}

p8: [p1a,p1b];

p8a:[a=A,b=B,c=C];

p8b:subst([p8a],p8);

p8c:subst(p7b5,p8b);

find : given  z=f(x,y) =x^2+y^2 ,' x=x0=1,y=y0=1 '
====================================
z0=x0^2+y0^2

p9:rhs(p3a1);

values :  
=====

x0:1;
y0:1;

f(x,y):= ''p9;

find : tangent plane
==============

p9a:ev(p7c2,nouns);
p9b:subst([z0=subst([x=x0,y=y0],p9)],p9a);
p9c:factor(p9b);
p9d:solve(p9c,z)[1];
p9d1:rhs(p9d);

to draw with wxplot3d:

draw 2: tangent plane
================

wxplot3d(p9d1,[x,-2,2],[y,-2,2]);

draw 3: surface @ tangent plane
========================

wxplot3d([f(x,y), p9d1,[x,-2,2],[y,-2,2]]);

find : normal line
==============

p10a:ev(p8c,nouns);
p10b:subst([z0=subst([x=x0,y=y0],p9)],p10a);
p10c:factor(%);

find : normal line and convert parametric plot
--------------------------------------------------------
t = parameter
----------------

1e) use parameter = t
----------------------------

p11a:lhs(p10a[1]) =t;
p11a1:rhs(p10a[1]) = t;
p11a2:lhs(p10b[2]) =t;

2e) solve x,y,z
-----------------

p11b:solve(p11a,x)[1];
p11b1:solve(p11a1,y)[1];
p11b2:solve(p11a2,z)[1];

3e) draw parametric line ,from 2e)
-----------------------------------------

wxdraw3d(color=blue,
   explicit(f(x,y),x,-4,4,y,-4,4),
color=red,
   implicit( p9d,x,-4,4,y,-4,4,z,0,4),
color=black,line_width=3,
    parametric(rhs(p11b),rhs(p11b1),rhs(p11b2),t,-1,1),
 color = blue, line_width=2,   
   parametric(1,1,t,t,0,20), 
    grid=true);

extra  option:proportional_axes=xyz,contour =both
see :http://people.kzoo.edu/barth/math214/SurfacePlaneLine.html

info : graph above.

blue   : f(x,y) =          :z=x^2+y^2                   ,'surface'
red    : tangent plane :z=2*y+2*x-2
black : normal line     :x=2*t+1,y=2*t+1,z=2-t

example : 3d ,use wxdraw3d
=====================

 wxdraw3d(
        contour = both,
        enhanced3d    = [sin(x),x,y],
        wired_surface = true,
        explicit(x^2+y^2,x,-4,4,y,-4,4),  
        enhanced3d    = [tan(x),x,y],
        explicit(p9d1,x,-4,4,y,-4,4) ,                  
        grid=true);