(* ::Package:: *)

BeginPackage["domain`"]


domain::usage="This package provides a function getBoxValue[] which computes the value of a box B=[-a,a]x[-a,a]x[-a,a] that represents the domain for the x,y,z coordinates of
the 3D space in which the stereographic projection of a plane complex algebraic curve can lie. The values of the box represents the minimal values for the x,y,z 
coordinates in the 3D space. Use ?getBoxValue for more information of the function."
getBoxValue::usage="The function getBoxValue[complexBivPolyEqn,{list_of_variables},value] takes as input a bivariate complex polynomial in two variables specified by
the list_of_variables and a positive real number specified by value. The function returns as output a value a for a box B=[-a,a]x[-a,a]x[-a,a] which represents the 
domain for the x,y and z coordinates of the 3D space in which the plane complex algebraic curve defined by complexBivPolyEqn can be projected using the generalized
projection method as specified in the package stereograpic. The boundary a for the box represents the minimal value for the box itself."


Begin["Private`"]
Share[];


getBoxValue[eqn_,{z_,w_},epsilon_]:=Block[{Global`x,Global`y,u,v,eqnnew,eqRe,eqIm,
eqSphere,vmax,boxValue,boxValuefinal},
eqnnew:=eqn/.{z->x+I*y,w->u+I*v};
eqRe:=ComplexExpand[Re[eqnnew]];
eqIm:=ComplexExpand[Im[eqnnew]];
eqSphere:=x^2+y^2+u^2+v^2-epsilon^2;
vmax:=NMaximize[{v,eqRe==0&&eqIm==0&&eqSphere==0},{x,y,u,v}];
boxValue:=Sqrt[(epsilon+vmax)/(epsilon-vmax)];
(*Print[boxValue];*)
boxValuefinal:=boxValue[[1]];
boxValuefinal
]


If[$Notebooks,
   CellPrint[Cell[#, "Print", FontColor -> Black, 
                              CellFrame -> 0.5, 
                              Background -> LightGray]]&,
   Print
  ]["domain - by Madalina Hodorog -  A package that uses computes a box B=[-a,a]x[-a,a]x[-a,a] which represents the minimal values
for the x,y,z coordinates in the 3D space for the stereographic projection of a plane complex algebraci curve."]


End[]
EndPackage[]
