> 
RationalTrigonometry:=module()
option package;
export
AcuteObstuseQ,
AcuteObstuseS,
AltitudeQ,
CircleParm,
CircumCirQ,
CfstoLeqn,
CrossLaw,
LinePrll,
LinePrpnd,
LinePts,
LPproj,
MedianQ,
#QPrj,
Quadrance,
Quadrea,
QQF,
SolidSpread,
SpreadLawQuadrea,
SpreadLaw,
SpreadPoly,
Spread,
Spreads123,
TQF,
TSF,
UHG;
local MyModule,RelDPxyz,ppp,xpsn,ypsn,zpsn;
MyModule:= module()
uses TT= TypeTools;
global _T1, _T2L, _T2V, _T2VR, _T3L, _T3V, _T3VC, _T3VR, _T4L, _MyType,GeomClr,Prntmsg, prjpsn;
GeomClr:="Blue";
Prntmsg:="y";
prjpsn:=3;
local
MyTypes:= {_T1, _T2L, _T2V, _T2VR, _T3L, _T3V, _T3VC, _T3VR, _T4L},
AllMyTypes:= MyTypes union {_MyType},
ModuleLoad,
ModuleUnload:= proc()
local T;
for T in AllMyTypes do if TT:Exists(T) then TT:RemoveType(T) end if; end do;
return
end proc;
ModuleLoad:= proc()
local
g, #iterator over module globals
e
;
ModuleUnload();
#op([2,6], ...) of a module is its globals.
for g in op([2,6], thismodule) do
e:= eval(g);
#print("e",e);
if g <> e and e in AllMyTypes then
error "The name %1 must be globally available.", g
end if
end do;
TT:AddType(_T1, algebraic);
TT:AddType(_T2V, 'Vector(2, algebraic)');
TT:AddType(_T2VR, 'Vector[row](2, algebraic)');
TT:AddType(_T2L, [algebraic $ 2]);
TT:AddType(_T3V, 'Vector(3, algebraic)');
TT:AddType(_T3VC, 'Vector[column](3, algebraic)');
TT:AddType(_T3VR, 'Vector[row](3, algebraic)');
TT:AddType(_T3L, [algebraic $ 3]);
TT:AddType(_T4L, [algebraic $ 4]);
TT:AddType(_MyType, MyTypes);
return
end proc;
export
WhichMyType:= proc(X)
local S:= select(T> X::T, MyTypes), n:= nops(S);
printf("%a is ", X);
if n=0 then printf("not any of the special types.\n")
else printf("type %a.\n", `if`(n=1, S[], Amd(S[])))
fi
end proc;
export
Dsp:= proc(msg:=" empty",prnt:=Prntmsg )
if prnt = "y" then print(msg); end if;
end proc;
ModuleLoad()
end module;
ppp:=proc(prjpsn)
description " the position x,y,z or z,x,y in a Vector";
if prjpsn=1 then
xpsn:=2;
ypsn:=3;
zpsn:=1;
else
xpsn:=1;
ypsn:=2;
zpsn:=3;
end if;
return xpsn, ypsn, zpsn
end proc;
#$include "Rational_Trigonometry\Quadruple Quad Formula.mpl"
#$include "Rational_Trigonometry\Quadrances_Overload_procs.mpl"
Quadrance :=overload([
# 1 Quadrances p0 [x,y]
proc(p0::{_T2L,_T2V}, clr := GeomClr,$)
option overload;
description "Calculates Quadrance of a [x,y] point";
uses LinearAlgebra;
if clr = "b" or clr = "B" or clr = "blue" or clr = "Blue" then
MyModule:Dsp(" Blue");
BilinearForm(p0, p0, conjugate = false) ;
elif clr = "r" or clr = "R" or clr = "red" or clr = "Red" then
MyModule:Dsp(" Red");
p0[1]^2  p0[2]^2 ;
elif clr = "g" or clr = "G" or clr = "green" or clr = "Green" then
MyModule:Dsp(" Green");
2*p0[1]*p0[2];
end if;
end proc,
# 7 Quadrances Point to Plane and intersection point 3D
proc(p0::{_T3L,_T3V},pl::{_T4L,`+`,procedure},var::_T3L:=[x,y,z],$)
option overload;
local i, dlambda,nlambda,lambda,Q ,intrP, Vpn ,f1 ;
if pl::_T4L then
Vpn:=convert(pl,Vector[row]);
elif pl::{`+`,procedure} then
f1 := `if`(pl::procedure, pl(vars[]), pl);
Vpn:=<coeff(f1,var[1]),coeff(f1,var[2]),coeff(f1,var[3]),coeff(coeff(coeff(f1,var[3],0),var[2],0),var[1],0)>;
end if;
nlambda:=(Vpn[1]*p0[1]+Vpn[2]*p0[2]+Vpn[3]*p0[3]+Vpn[4]);
dlambda:=Vpn[1]^2+Vpn[2]^2+Vpn[3]^2;
lambda:=nlambda/dlambda;
intrP:=`<>`(seq(p0[i]+lambda*Vpn[i],i=1..3));
Q:=nlambda^2/dlambda;
MyModule:WhichMyType(pl);
MyModule:Dsp("Quadrance Point to Plane & intersect Point");
return Q,intrP
end proc,
# 2 Quadrances p0 [x,y,z]
proc(p0::{_T3L,_T3V}, clr := GeomClr,$)
option overload;
description "Calculates Quadrance of a [x,y,z] point Blue only";
uses LinearAlgebra;
if clr = "b" or clr = "B" or clr = "blue" or clr = "Blue" then
MyModule:Dsp("Quadrance 3D Point Blue");
BilinearForm(p0, p0, conjugate = false);
else print("3D Not yet implimented for Red or Green Geometry" );
end if;
end proc,
# 3 Quadrances P0P1 [x,y]
proc(p0::{_T2L,_T2V},p1::{_T2L,_T2V}, clr := GeomClr,$)
option overload;
description "Quadrance between two [x,y] points";
uses LinearAlgebra;
if clr = "b" or clr = "B" or clr = "blue" or clr = "Blue" then
MyModule:Dsp( "Quadrance between two 2D Points Blue") ;
BilinearForm(p0  p1, p0  p1, conjugate = false);
elif clr = "r" or clr = "R" or clr = "red" or clr = "Red" then
MyModule:Dsp( "Quadrance between two 2D Points Red") ;
(p0[1]  p1[1])^2  (p0[2]  p1[2])^2;
elif clr = "g" or clr = "G" or clr = "green" or clr = "Green" then
MyModule:Dsp( "Quadrance between two 2D Points Green") ;
(2*p1[1]  2*p0[1])*(p1[2]  p0[2]);
end if;
end proc,
# 4 Quadrances p0p1 [x,y,z]
proc(p0::{_T3L,_T3V},p1::{_T3L,_T3V}, clr::string := GeomClr,$)
option overload;
description "Calculates Quadrance of between two points/vectors [x,y,z] Blue only";
uses LinearAlgebra;
if clr = "b" or clr = "B" or clr = "blue" or clr = "Blue" then
MyModule:Dsp( "Quadrance between two 3D Points Blue") ;
BilinearForm(p0  p1, p0  p1, conjugate = false);
else print("Not at this point implimented for Red or Green Geometry" );
end if;
end proc,
# 5 Quadrances Point to Line and intersection point 2D
proc(p0::_T2L, l1::{_T3L,`+`,procedure}, vars::_T2L:=[x,y],clr:=GeomClr)
option overload;
local f1,P0:=p0,P1;
if l1::_T3L then
P1:=l1;
else
f1 := `if`(l1::procedure, l1(vars[]), l1);
P1:=[coeff(f1,vars[1]),coeff(f1,vars[2]),coeff(coeff(f1,vars[1],0),vars[2],0)];
end if;
if clr = "b" or clr = "B" or clr = "blue" or clr = "Blue" then
MyModule:Dsp( "Quadrance 2D Point to Line & intersect Point Blue") ;
return (P0[1]*P1[1] + P0[2]*P1[2] + P1[3])^2/(P1[1]^2 + P1[2]^2),
[((P0[2]*P1[2]  P1[3])*P1[1] + P0[1]*P1[2]^2)/(P1[1]^2 + P1[2]^2),
((P0[1]*P1[1]  P1[3])*P1[2] + P0[2]*P1[1]^2)/(P1[1]^2 + P1[2]^2)];
elif clr = "r" or clr = "R" or clr = "red" or clr = "Red" then
if P1[1]^2  P1[2]^2 <> 0 then
MyModule:Dsp( "Quadrance 2D Point to Line & intersect Point Red") ;
return (P0[1]*P1[1] + P0[2]*P1[2] + P1[3])^2/(P1[1]^2  P1[2]^2),
[((P0[2]*P1[2]  P1[3])*P1[1]  P0[1]*P1[2]^2)/(P1[1]^2  P1[2]^2),
((P0[1]*P1[1] + P1[3])*P1[2] + P0[2]*P1[1]^2)/(P1[1]^2  P1[2]^2)];
else
"Null Red"
end if;
#"Input ERROR "Red"";
elif clr = "g" or clr = "G" or clr = "green" or clr = "Green" then
if P1[1]*P1[2] = 0 then
"Null Green";
else
MyModule:Dsp( "Quadrance 2D Point to Line & intersect Point Green") ;
return 1/2*(P0[1]*P1[1] + P0[2]*P1[2] + P1[3])^2/(P1[1]*P1[2]),
[1/2*(P0[1]*P1[1]  P0[2]*P1[2]  P1[3])/P1[1],
1/2*(P0[1]*P1[1] + P0[2]*P1[2]  P1[3])/P1[2]];
end if;
else
"Input ERROR Green";
end if;
end proc,
# 6 Quadrances Point to Line and intersection point 3D
proc(p0::{_T3L,_T3V},lP::{_T3L,_T3V},lV::{_T3V},$)
option overload;
local lambda , Q ,intrP ;
lambda:=((p0[1]lP[1])*lV[1]+(p0[2]lP[2])*lV[2]+(p0[3]lP[3])*lV[3])/(lV[1]^2+lV[2]^2+lV[3]^2);
print(lambda);
Q:=((p0[1]lP[1]lambda*lV[1])^2+(p0[2]lP[2]lambda*lV[2])^2+(p0[3]lP[3]lambda*lV[3])^2);
intrP:=lP+lambda*lV;
MyModule:Dsp("Quadrance Point to 3D Line and Intersect Point");
return Q,intrP
end proc
]):
QQF := proc(Q1, Q2, Q3, Q4)
((Q1 + Q2 + Q3 + Q4)^2  2*Q1^2  2*Q2^2  2*Q3^2  2*Q4^2)^2 = 64*Q2*Q1*Q3*Q4;
end proc;
end module:
