(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



(* par Marcel D\[EAcute]l\[EGrave]ze *)


BeginPackage["TraceGraphiques`"]


fenetre::usage=
	"fenetre[xmin, xmax, ymin, ymax] ouvre une fen\[EHat]tre graphique ImageSize\[Rule]{500,500}.
	fenetre[xmin, xmax, ymin, ymax,{s1,s2}] ouvre une fen\[EHat]tre graphique  ImageSize\[Rule]{s1,s2}."


droite::usage=
	"droite[a, b, c, options] construit le graphique de la droite\n d'\[EAcute]quation a x + b y + c = 0.\n Les options (facultatives) sont celles de Line."


fonction::usage=
	"fonction[f,{{\!\(\*SubscriptBox[\"a\", \"1\"]\), \!\(\*SubscriptBox[\"b\", \"1\"]\)}, ..., {\!\(\*SubscriptBox[\"a\", \"n\"]\), \!\(\*SubscriptBox[\"b\", \"n\"]\)}}, options] construit le graphique\n de la fonction f sur chaque intervalle ]\!\(\*SubscriptBox[\"a\", \"1\"]\), \!\(\*SubscriptBox[\"b\", \"1\"]\)[, ...,]\!\(\*SubscriptBox[\"a\", \"n\"]\), \!\(\*SubscriptBox[\"b\", \"n\"]\)[.\n Les options (facultatives) sont celles de Show."


dessine::usage=
	"dessine[\!\(\*SubscriptBox[\"g\", \"1\"]\), \!\(\*SubscriptBox[\"g\", \"2\"]\), ..., \!\(\*SubscriptBox[\"g\", \"k\"]\), options] fait appara\[IHat]tre les objets graphiques\n \!\(\*SubscriptBox[\"g\", \"1\"]\), ..., \!\(\*SubscriptBox[\"g\", \"k\"]\) dans la fen\[EHat]tre courante.\n
		Les options (facultatives) sont celles de Show."


hachure::usage=
	"hachure[f, g, a, b] construit des hachures verticales entre la fonction inf\[EAcute]rieure f\n et la fonction sup\[EAcute]rieure g entre les bornes a et b.\n
		hachure[g, a, b] construit des hachures entre l'axe des x\n
		et la fonction positive g entre les bornes a et b."


hachureHoriz::usage=
	"hachureHoriz[eg, ed, y1, y2] construit des hachures horizontales entre la courbe de gauche d'\[EAcute]quation eg\n et la courbe de droite d'\[EAcute]quation ed entre les bornes y1 et y2."


Begin["`Private`"]


fenetre[a_,b_,c_,d_]:=(xmin=a;xmax=b;ymin=c;ymax=d;xs=500;ys=500;);


fenetre[a_,b_,c_,d_,{s1_,s2_}]:=(xmin=a;xmax=b;ymin=c;ymax=d;xs=s1;ys=s2;);


droite[a_,b_,c_]:=Graphics[{Line[{{xmin,(-a xmin-c)/b},{xmax,(-a xmax-c)/b}}]}]/;Abs[b]>Abs[a]


droite[a_,b_,c_]:=Graphics[{Line[{{(-b ymin-c)/a,ymin},{(-b ymax-c)/a,ymax}}]}]


droite[a_,b_,c_,opt__]:=Graphics[{opt,Line[{{xmin,(-a xmin-c)/b},{xmax,(-a xmax-c)/b}}]}]/;Abs[b]>Abs[a]


droite[a_,b_,c_,opt__]:=Graphics[{opt,Line[{{(-b ymin-c)/a,ymin},{(-b ymax-c)/a,ymax}}]}]


cadre[df_List]:=Module[{eps},eps=(xmax-xmin)/10^5;	
		critQ[{a_,b_}]:=a<b;
	Select[Table[{Max[df[[k]][[1]],xmin]+eps,Min[df[[k]][[2]],xmax]-eps},
				{k,1,Length[df]}],critQ]]


fonction[f_,df_List,opt___]:=Module[{i},i=cadre[df];
		Show[Table[Plot[f[t],{t,i[[k]][[1]],i[[k]][[2]]},
					opt,Compiled->False,
					PlotRange->{ymin,ymax},DisplayFunction->Identity],{k,1,Length[i]}]]]


inf[f_List][x_]:=Max[Through [f[x]]];
inf[f_][x_]:=f[x]


sup[g_List][x_]:=Min[Through [g[x]]];
sup[g_][x_]:=g[x]


hachure[f_,g_,a_,b_]:=Module[{n,k,h,x},
		n=Round[200*xs/500];(*200 lignes sur une largeur de 500*)
		h=(xmax-xmin)/n;
		x=Select[Table[k,{k,Max[a,xmin],Min[b,xmax],h}],Function[t, sup[g][t]-inf[f][t]>=0]];
		Graphics[{Thickness[0.001] ,Table[Line[{{x[[k]],inf[f][x[[k]]]},{x[[k]],sup[g][x[[k]]]}}],{k,1,Length[x]}]}]]


o[x_]:=0;
hachure[g_,a_,b_]:=hachure[o,g,a,b]


hachureHoriz[rg_,rd_,y1_,y2_]:=Module[{x,y,n},xg[y_]:=Max[x/.Solve[(rg[x,y])\[Or]x==xmin,x]];xd[y_]:=Min[x/.Solve[(rd[x,y])\[Or]x==xmax,x]];n=Round[200*ys/500];Graphics[{Thickness[0.001],DeleteCases[Table[Map[Line,Select[{{{xg[y],y},{xd[y],y}}},Function[z,z[[1,1]]<z[[2,1]]]]],{y,Max[y1,ymin],Min[y2,ymax],(ymax-ymin)/n}],{}]}]]


dessine[f__]:=Show[f,PlotRange->{{xmin,xmax},{ymin, ymax}},
		Axes->True,
		ImageSize->{xs,ys},
		DisplayFunction->$DisplayFunction]


End[]


EndPackage[]
