kill(all)$

maxima : example general quadratic form : parabola , version 1.0a
peter.vlasschaert@gmail.com,18/05/2022

need : appendix , general equation : Y^2=4*P*Y
P : related to the focus of the parabola.

step 1: input quadratic form.
-----------------------------------

p1: 9*x^2-24*x*y+16*y^2-18*x-101*y+19=0;

fig1 :p1

plot : quadratic form : p1

wxplot2d ([p1], [x, -7, 7], [y, -7, 7],
    grid2d,nobox,[yx_ratio, 1])$

step 2: parts of quadratic form.
---------------------------------------

quadratic form : three parts
-----------------------------------

→ part 1: (qua)dratic part.
----------------------------------

quapart(pp):=block([],
    ra:sort(listofvars(pp)),
    pp:lhs(pp),
    r1:ratcoeff(pp,(ra[1])^2),r1a:r1*(ra[1])^2,
    r2:ratcoeff(pp,ra[1]*ra[2]),r2a:r2*(ra[1])*(ra[2]),
    r3:ratcoeff(pp,(ra[2])^2),r3a:r3*(ra[2])^2,
    return([ra,[r1a+r2a+r3a],[r1,r2,r3]])
)$

p2:quapart(p1);

p2a1:factor(p2[2]);

p2a2:facsum(p2[2])[1];

→ part2: (lin)ear part.
---------------------------

linpart(pp):=block([],
 raa:sort(listofvars(pp)),
    pp:lhs(pp)-quapart(pp)[2],
    rr1:ratcoeff(pp,(ra[1])),r1aa:rr1*(ra[1]),
    rr2:ratcoeff(pp,ra[2]),r2aa:rr2*(ra[2]),
    return([raa,[r1aa+r2aa],[rr1,rr2]])
)$

p3:linpart(p1);

p3a:p3[2][1][1];

→ part3: (const)ant part.
------------------------------

constpart(pp):=block([],
     rbb:sort(listofvars(pp)),
     pp:lhs(pp),
     r4:subst(makelist(rbb[i]=0,i,1,length(rbb)),pp),
    return(r4)
)$

p4:constpart(p1);

step 3:new p1
-----------------

use:p2a2 & {p3(p3a),p4}

p5:p2a2=-p3a-p4;

p5a:part(lhs(p5),1);

step 4: arbitrary value :λ
-------------------------------

a)  λ inside : quadratic.
----------------------------

p6a:(p5a+λ)^2;

 first : linear equation

p6a1:part(p6a,1) =0;

p6b:p6a=lhs(p5)+v;

b) solve : p6b for v
------------------------

p6c:solve(p6b,v);

p6d:subst(p6c,p6b);

p6d1:expand(p6d);

check:

p6d1a:is(p6d1);

c) v & p5 into p6b
----------------------

p6e:flatten([p5,p6c]);

p6f:subst(p6e,p6b);

d) rhs : A*x+B*y +C
-------------------------

p6g:listofvars(p6f);

p6g1:lhs(p6f)=ratcoeff(rhs(p6f),p6g[1])*p6g[1]+
ratcoeff(rhs(p6f),p6g[2])*p6g[2]+subst([p6g[1]=0,p6g[2]=0],rhs(p6f));

step 5: how to find λ.
---------------------------

≥ first & second : linear eq.

→ second : linear equation

p6h1:subst([p6a1],p6g1);

→ given : p6a1
( first : linear equation)

≥ rico: m1:first eq,m2:second eq.

→ m1

p6h2:expand(solve(p6a1,p6g[2]))[1];

p6h2a:m1=ratcoeff(rhs(p6h2),p6g[1]);

→ m2

p6i2:solve(p6h1,p6g[2])[1];

p6i2a:m2=ratcoeff(rhs(p6i2),p6g[1]);

≥ constraint : m1*m2 = -1

p6j:rhs(p6h2a) *rhs(p6i2a) = -1;

p6ja:solve(p6j,listofvars(p6j));

step 6: λ into p6f
---------------------

p7a:subst(p6ja,lhs(p6f)) =factor(expand(subst(p6ja,rhs(p6f))));

p7a1:part(lhs(p7a),1)=0;

→ norm : first eq.

p7a11:sqrt((ratcoeff(lhs(p7a1),p6g[1]))^2+(ratcoeff(lhs(p7a1),p6g[2]))^2);

p7a2:part(rhs(p7a),2)=0;

→ norm : second eq.

p7a22:sqrt((ratcoeff(lhs(p7a2),p6g[1]))^2+(ratcoeff(lhs(p7a2),p6g[2]))^2);;

fig 2 : red -green

wxplot2d ([p1,p7a1,p7a2], [x, -8, 8], [y, -8, 8],
    grid2d,nobox,[yx_ratio, 1])$

appendix : parabola  Y^2=4*P*X, parabola : open  x-direction

(x,y) → (X, Y)

step 7: find P
----------------

p8:4*P = part(rhs(p7a),1)/p7a11;

p8a:solve(p8,listofvars(p8))[1];

step 8: Y^2=4*P*X
------------------------

p9aa: Y^2=4*P*X ;

step 8: (x,y) →(X,Y)

p9aax:reverse(X=lhs(p7a2)/p7a22);

p9aay:reverse(Y=lhs(p7a1)/p7a11);

the axis :fig 2

→ first axis : @X=0

p9aaxx:subst([X=0],p9aax);/*red : line*/

→ second axis : @Y=0

p9aayy:subst([Y=0],p9aay);/*green : line*/

fig 3:

wxplot2d ([p1,p9aaxx,p9aayy], [x, -8, 8], [y, -8, 8],
    grid2d,nobox,[yx_ratio, 1])$

rem : fig2 = fig3

intersection (green,red) : top of the parabola:

p9bb:flatten(solve([p9aaxx,p9aayy],listofvars([p9aaxx,p9aayy])));

step 9:focus : X =P, Y=0
-----------------------------

p10a1:[p9aax,p9aay];

p10a2:subst([Y=0,X=rhs(p8a)],p10a1);

p10a3:flatten(solve(p10a2,listofvars(p10a2)));

step 10:find intersection parabola: x-axis & y-axis
-------------------------------------------------------------

→ intersection : x-axis . y=0, p1

p11ax1:subst([y=0],p1);

p11ax2:float(solve(p11ax1,listofvars(p11ax1)));

rem : p11ax2 are complex , no intersection with x-axis

→ intersection : y-axis . x=0, p1

p11ay1:subst([x=0],p1);

p11ay2:float(solve(p11ay1,listofvars(p11ay1)));

rem : two intersection with y-axis.

≥ first point

p11ayp1:[0,rhs(p11ay2[1])];

see fig :3

≥ second point

p11ayp2:[0,rhs(p11ay2[2])];

see fig : 3

step 11:directrix 
---------------------

------------------------------------------------------------

a) need postion (x,y) system : focus = (xf,yf).
b) need postion (x,y) system : top    = (xt,yt).
c) equation mid point 
d) red line : rico= mm same direction as : directrix

-------------------------------------------------------------

a) position :focus,p10a3

p12a1:xf=rhs(p10a3[1]);
p12a2:yf=rhs(p10a3[2]);

p12a3:[p12a1,p12a2];

b) position :top,p9bb

p12b1:xt=rhs(p9bb[1]);
p12b2:yt=rhs(p9bb[2]);

p12b3:[p12b1,p12b2];

c) midpoint equations :

p12c:flatten([p12a3,p12b3]);

p12c1: [xt = (x+xf)/2,yt = (y+yf)/2];

p12c2:subst(p12c,p12c1);

p12c3:flatten(solve(p12c2,listofvars(p12c2)));

d) directrix y = rico(red line)*x+n
n = unknown

→ same : rico=mm, red line : fig 3

p12d1 : y=mm*x+n;

find : mm ,redline p9aaxx

p12d2:num(lhs(p9aaxx))=0;

p12d3:[mm=ratcoeff(rhs(solve(p12d2,y)[1]),x)];

p12d4:flatten([p12d3,p12c3]);

p12d5:subst(p12d4,p12d1);

p12d6:solve(p12d5,n);

p12d7:flatten([p12d3,p12d6]);

p12d8:subst(p12d7,p12d1);

wxplot2d ([p1,p9aaxx,p9aayy,p12d8], [x, -7, 7], [y, -7, 7],
    grid2d,nobox,[yx_ratio, 1])$

rem : purple line : directrix, (x,y) plane.

step 12: line perpendicular to green-axis trough the focus,length,intersection.
-----------------------------------------------------------------------------------------------

→ same : rico :mm , red line // purple line : use p12d1: n→ n1

p13a1:subst([n=n1],p12d1);

→ use : mm (=p12d3)

p13a2:subst(p12d3,p13a1);

→ use :coordinates focus (xf,yf) → find : n1

p13a3:subst([x=xf,y=yf],p13a2);

p13a4:solve(p13a3,n1);

p13a5:subst(p12a3,p13a3);

p13a6:solve(p13a5,listofvars(p13a5));

→ perpendicular line trough the focus.

p13a7:subst(p13a6,p13a2);

fig 4:perpendicular line (color=black) trough the focus.

wxplot2d ([p1,p9aaxx,p9aayy,p12d8,p13a7], [x, -7, 7], [y, -7, 7],
    grid2d,nobox,[yx_ratio, 1])$

≥ find intersection (parabola:p1, black line)

use : p13a7

p13b1:ratexpand(subst(p13a7,p1));

intersection : solve p13b1 for x

p13b2:solve(p13b1,listofvars(p13b1));

highest point (intersection): above x-axis (see:fig 4)

p13b3a:xh=rhs(p13b2[2]);
p13b3a1:yh=rhs(subst([x=rhs(p13b3a)],p13a7));

lowest point (intersection): above x-axis (see:fig 4)

p13b3b:xl=rhs(p13b2[1]);
p13b3b1:yl=rhs(subst([x=rhs(p13b3b)],p13a7));

L=length line :|(xl,yl)-(xh,yh)|

p13c1:flatten([p13b3a,p13b3a1,p13b3b,p13b3b1]);

p13c2:L =(subst(p13c1,sqrt((xh-xl)^2+(yh-yl)^2)));

check : p8a L =4*P

p13c3:p8;

is(rhs(p13c2)=rhs(p13c3));

------------------------------------------------------------------------------------------