kill(all)$

maxima: proof distance from point to line,version 1.0
peter.vlasschaert@gmail.com,23/09//2020

ref : general youtube , 'google search'
ref :  https://en.wikipedia.org/wiki/Cross_product

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

load(lrats)$ ratprint:false$

first :step (find coordinates,A,B)
========================

a) given : equation of line (L1 ,see Figure).
----------------------------------------------------------

p1: a*x+b*y+c = 0;
p1a:solve(p1,y)[1],expand;

b)  point  A(x1,y1),y=0
------------------------------

p1b:[y=0];
p1b1:lratsubst(p1b,p1a),expand;

p1b2:solve(p1b1,x)[1];

p1b3:[rhs(p1b2),rhs(p1b)];/* (xa,ya)*/

p1b4:[xa=p1b3[1],ya=p1b3[2]];

c)  point  B(x2,y2),x=0
------------------------------

p1c:[x=0];
p1c1:lratsubst(p1c,p1a),expand;

p1c2:[rhs(p1c),rhs(p1c1)];/*(xb,yb)*/

p1c4:[xb=p1c2[1],yb=p1c2[2]];

second :step : d =distance ( A,B)
==========================

a) distance :equation , make definition 'maxima'
-----------------------------

p1d:dist(xa,ya,xb,yb):=sqrt((xa-xb)^2+(ya-yb)^2);

b) insert values A,B in a)
-----------------------------------

p1d1:append(p1b4,p1c4);

p1d2:d=lratsubst(p1d1,dist(xa,ya,xb,yb));

p1d3:lratsubst([abs(a)=a,abs(b)=b,abs(c)=c],p1d2);

p1d3:'reason to do  this , because we needed to do this for simplication ,ar,h
see :below.

third :step : area triangle Δ(A,B,C)
===========================

a) area formula  Δ (A,B,C) =ar
-----------------------------------------

p1e:ar=1/2*h*d;

p1e1:solve(p1e,h)[1];

b) points on Δ (A,B,C)
-------------------------------

p1e2:[x3,y3];/* point outside  : L1 */
p1e2a:flatten([p1b3,p1c2,p1e2]);

p1e2b:makelist([concat(x,i),concat(y,i)],i,1,length(p1e2a)/2);

p1e2b1:flatten(p1e2b);

→ coordinates points :Δ(A,B,C)

p1e2c:map("=",p1e2b1,p1e2a);

c) cross product to find :area triangle.
---------------------------------------------------

→  c1= vector (AB) , (x1,y1) → (x2,y2)  => (x2-x1,y2-y1)
→  b1 =vector(AC) ,  (x1,y1) → (x3,y3) =>  (x3-x1,y3-y1)
------------------------------------------------------------------------------
rem    →  :cross product :between vectors,see wikipedia
------------------------------------------------------------------------------
abs(cross product(AB,AC) ) = area Parallellogram
------------------------------------------------------------------------------
→ https://nl.wikipedia.org/wiki/Parallellogram
→ https://en.wikipedia.org/wiki/Parallelogram

vector notation : i,j = unit vectors (along ,x-axis,y-axis)
-------------------------------------------------------------------------
2d :r =x*i+y*j  , 3d ::r =x*i+y*j +z*k  , k = along z-axis

vec(r) = x*(i)+y*(j);

p1fa:vec(AB) = (x2-x1)*i+(y2-y1)*j;
p1fb:vec(AC) = (x3-x1)*i+(y3-y1)*j;

rem :cross product : result vector , perpendicular above the 
         plane from vec(AB),vec(AC) , result :vector in  the direction of the z-axis.
----------------------------------------------------------------------------------------------------------
reason : vec(AB),vec(AC) are vectors inside the xy plane .

→  create matrix (3 by 3), triangle. ' menu ' ,Algebra, Enter matrix.

m1:matrix(
 [i,j,k], 
 [ux,uy,uz], 
 [vx,vy,vz]
);

→ uv = u x v, cross product .'definition'

uv(ux,uy,uz,vx,vy,vz):=matrix(
 [i,j,k], 
 [ux,uy,uz], 
 [vx,vy,vz]
);

→ insert  vec(AB),vec(AC).

p2a:ux=ratcoef(rhs(p1fa),i);
p2b:uy=ratcoef(rhs(p1fa),j);
p2c:uz=1;
p2:[p2a,p2b,p2c];

p3a:vx=ratcoef(rhs(p1fb),i);
p3b:vy=ratcoef(rhs(p1fb),j);
p3c:vz=1;
p3:[p3a,p3b,p3c];

→ p2 & p3

p4:append(p2,p3);

→ coef : k

p5:lratsubst(p4,uv(ux,uy,uz,vx,vy,vz));

p5a:determinant(p5);

→ area, Δ(A,B,C), reason division by 2, for the triangle.

p5b:ar=ratcoef(p5a,k)/2;

p5c:lratsubst(p1e2c,p5b);

fourth :step :distance h ,see figure1.
===========================
use :p1e1

p6:p1e1;

p6a:[p5c,p1d3];

perpendicular distance : (x3,y3)  to L1,see figure 1,'above'

p6b:lhs(p6)=abs(lratsubst(p6a,rhs(p6)));

rem : vector product = cross product