summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex')
-rw-r--r--macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex346
1 files changed, 344 insertions, 2 deletions
diff --git a/macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex b/macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex
index 65ec863b11..bb21fbb6ae 100644
--- a/macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex
+++ b/macros/latex/contrib/profcollege/latex/PfCNotionFonction.tex
@@ -1,7 +1,7 @@
%%%
% Fonction
%%%
-\setKVdefault[ClesFonction]{Nom=f,Variable=x,Calcul=x,Tableau=false,Largeur=5mm,Ecriture=false,Definition=false,Points=false,Tangentes=false,PasX=1,PasY=1,UniteX=1,UniteY=1,Prolonge=false,Trace=false,Catmull=false,Epaisseur=1,Couleur=black,CouleurTrace=black,PointsCourbe=true,Codes=false,Origine={(0,0)},Vide=false}
+\setKVdefault[ClesFonction]{Nom=f,Variable=x,Calcul=x,Tableau=false,Largeur=5mm,Ecriture=false,Definition=false,Points=false,Tangentes=false,PasX=1,PasY=1,UniteX=1,UniteY=1,Prolonge=false,Trace=false,Catmull=false,Splines=false,Epaisseur=1,Couleur=black,CouleurTrace=black,PointsCourbe=true,Codes=false,Origine={(0,0)},Vide=false}
\defKV[ClesFonction]{Traces=\setKV[ClesFonction]{Codes}}%
\newtoks\toklistePtsFn%pour la discipline
@@ -38,6 +38,80 @@
\toklistePtsFn{}%
\setsepchar[*]{§*/}%\ignoreemptyitems%
\readlist*\ListePoints{#2}%
+ \ifboolKV[ClesFonction]{Splines}{%
+ \xdef\PfCFooListePoints{}%
+ \foreachitem\compteur\in\ListePoints{%
+ \xdef\PfCFooListePoints{\PfCFooListePoints (\ListePoints[\compteurcnt,2],\ListePoints[\compteurcnt,3]),(\ListePoints[\compteurcnt,1],\ListePoints[\compteurcnt,4]),}%
+ }%
+ \MPSpline{\PfCFooListePoints}{\useKV[ClesFonction]{PasX}}{\useKV[ClesFonction]{PasY}}{\useKV[ClesFonction]{UniteX}}{\useKV[ClesFonction]{UniteY}}%
+ }{%
+ \ifboolKV[ClesFonction]{Catmull}{%
+ \xdef\PfCFooListePoints{(\ListePoints[1,2],\ListePoints[1,3]),}%
+ \foreachitem\compteur\in\ListePoints{%
+ \xdef\PfCFooListePoints{\PfCFooListePoints (\ListePoints[\compteurcnt,2],\ListePoints[\compteurcnt,3]),}%
+ }%
+ \xdef\PfCFooListePoints{\PfCFooListePoints (\ListePoints[\ListePointslen,2],\ListePoints[\ListePointslen,3]),}%
+ \MPCatmull{\PfCFooListePoints}{\useKV[ClesFonction]{PasX}}{\useKV[ClesFonction]{PasY}}{\useKV[ClesFonction]{UniteX}}{\useKV[ClesFonction]{UniteY}}%
+ }{%
+ \xdef\PfCFooListePoints{}
+ \ifboolKV[ClesFonction]{Tangentes}{%
+ \foreachitem\compteur\in\ListePoints{%
+ \xdef\PfCFooListePoints{\PfCFooListePoints \ListePoints[\compteurcnt,1],(\ListePoints[\compteurcnt,2],\ListePoints[\compteurcnt,3]),\ListePoints[\compteurcnt,4],}%
+ }%
+ }{%
+ \foreachitem\compteur\in\ListePoints{%
+ \xdef\PfCFooListePoints{\PfCFooListePoints (\ListePoints[\compteurcnt,2],\ListePoints[\compteurcnt,3]),}%
+ }%
+ }%
+ \MPCourbeNew{\PfCFooListePoints}%
+ }%
+ }%
+ }{%
+ \setsepchar{,}\ignoreemptyitems%
+ \readlist*\ListeFonction{#2}%
+ \StrSubstitute{\useKV[ClesFonction]{Calcul}}{\useKV[ClesFonction]{Variable}}{\i}[\temp]%
+ \StrSubstitute{\useKV[ClesFonction]{Calcul}}{**}{^}[\tempa]%
+ \StrSubstitute{\tempa}{*}{}[\tempab]%
+ \ifboolKV[ClesFonction]{Ecriture}{%
+ \ensuremath{\useKV[ClesFonction]{Nom}(\useKV[ClesFonction]{Variable})=\tempab}%
+ }{}%
+ \ifboolKV[ClesFonction]{Definition}{%
+ \ensuremath{\useKV[ClesFonction]{Nom}:\useKV[ClesFonction]{Variable}\mapsto\tempab}%
+ }{}%
+ \ifboolKV[ClesFonction]{Tableau}{%
+ \buildtabfonction%
+ }{}%
+ \reademptyitems%
+ }%
+ }%
+}%
+
+\NewDocumentCommand\Fonctionold{o m}{%
+ \useKVdefault[ClesFonction]%
+ \setKV[ClesFonction]{#1}%
+ \ifboolKV[ClesFonction]{Trace}{%
+ \useKVdefault[TraceG]%
+ \setKV[TraceG]{#1}%
+ \tokPfCListeDesFonctions{}%
+ \tokPfCListeDesNomsFonctions{}%
+ \xdef\PfCFooFn{\useKV[ClesFonction]{Calcul}}
+ \xdef\PfCFooNomFn{\useKV[TraceG]{NomCourbe}}
+ \ifx\bla\PfCFooFn\bla%
+ \else
+ \readlist*\ListeDesFonctions{\PfCFooFn}
+ \foreachitem\compteur\in\ListeDesFonctions{\expandafter\UpdatePfCListeDesFonctions\compteur\nil}%
+ \fi
+ \ifx\bla\PfCFooNomFn\bla
+ \else
+ \readlist*\ListeDesNomsFonctions{\PfCFooNomFn}
+ \foreachitem\compteur\in\ListeDesNomsFonctions{\expandafter\UpdatePfCListeDesNomsFonctions\compteur\nil}%
+ \fi
+ \TraceMultiGraphique{\the\tokPfCListeDesFonctions}{\the\tokPfCListeDesNomsFonctions}%
+ }{%
+ \ifboolKV[ClesFonction]{Points}{%
+ \toklistePtsFn{}%
+ \setsepchar[*]{§*/}%\ignoreemptyitems%
+ \readlist*\ListePoints{#2}%
\ifboolKV[ClesFonction]{Catmull}{%
\xdef\PfCFooListePoints{(\ListePoints[1,2],\ListePoints[1,3]),}%
\foreachitem\compteur\in\ListePoints{%
@@ -60,7 +134,7 @@
}%
}{%
\setsepchar{,}\ignoreemptyitems%
- \readlist*\ListeFonction{#2}%
+ \roeadlist*\ListeFonction{#2}%
\StrSubstitute{\useKV[ClesFonction]{Calcul}}{\useKV[ClesFonction]{Variable}}{\i}[\temp]%
\StrSubstitute{\useKV[ClesFonction]{Calcul}}{**}{^}[\tempa]%
\StrSubstitute{\tempa}{*}{}[\tempab]%
@@ -78,6 +152,274 @@
}%
}%
+\def\MPSplineCode{%
+ boolean PointsCourbe,Code,Prolonge;
+ PointsCourbe=\useKV[ClesFonction]{PointsCourbe};
+ Code=\useKV[ClesFonction]{Codes};
+ Prolonge:=\useKV[ClesFonction]{Prolonge};
+ color CoulTrace;
+ CoulTrace:=\useKV[ClesFonction]{CouleurTrace};
+ Epaisseur:=\useKV[ClesFonction]{Epaisseur};
+ %
+ vardef EffectuerTraces=
+ \useKV[ClesFonction]{Traces};
+ enddef;
+%
+ def enplace=
+ xscaled X.u yscaled Y.u
+ enddef;
+ %
+ vardef placepoint(expr q,r)=
+ (q,r)*cm enplace
+ enddef;
+ %
+ nbspline=0;
+ %
+ nbpoints=50;
+ %
+ vardef SplineCubique(expr xzero,yzero,xuno,yuno,dzero,duno)=
+ nbspline:=nbspline+1;
+ a[nbspline]*(xzero**3)+b[nbspline]*(xzero**2)+c[nbspline]*xzero+d[nbspline]=yzero;
+ a[nbspline]*(xuno**3)+b[nbspline]*(xuno**2)+c[nbspline]*xuno+d[nbspline]=yuno;
+ a[nbspline]*(3*(xzero**2))+b[nbspline]*(2*xzero)+c[nbspline]=dzero;
+ a[nbspline]*(3*(xuno**2))+b[nbspline]*(2*xuno)+c[nbspline]=duno;
+ %
+ numeric xx[],yy[];
+ for k=1 upto nbpoints-1:
+ xx[k]=xzero+(k/nbpoints)*(xuno-xzero);
+ yy[k]=a[nbspline]*(xx[k]**3)+b[nbspline]*(xx[k]**2)+c[nbspline]*xx[k]+d[nbspline];
+ endfor;
+ save $;
+ picture $;
+ $=image(
+ draw placepoint(xzero,yzero) for k=1 upto nbpoints-1:
+ --placepoint(xx[k],yy[k])
+ endfor --placepoint(xuno,yuno);
+ );
+ $
+ enddef;
+}
+
+\def\MPSpline#1#2#3#4#5{%
+ % #1 la liste des points
+ % #2: pas en x
+ % #3: pas en y
+ % #4: unit\'e en x
+ % #5: unit\'e en y
+ \ifluatex
+ \mplibforcehmode
+ \begin{mplibcode}
+ \MPSplineCode;
+
+ x.u:=#2;
+ y.u:=#3;
+ X.u:=#4;
+ Y.u:=#5;
+
+ pair Xn[],Fn[],Dn[];%Xn abscisse,ordonnée D : dérivé g,dérivée d
+ n=0;
+ for p_=#1:
+ n:=n+1;
+ if (n mod 2)=1:
+ Xn[(n div 2)+1]=p_;
+ Fn[(n div 2)+1]=cm*(X.u*xpart(p_),Y.u*ypart(p_));
+ else:
+ Dn[(n div 2)]=p_
+ fi;
+ endfor;
+ N:=n div 2;
+ MinX=999;
+ MaxX=-999;
+ MinY=999;
+ MaxY=-999;
+ if Prolonge:
+ debutbalai=2;
+ finbalai=N-1;
+ else:
+ debutbalai=1;
+ finbalai=N;
+ fi;
+ for k=debutbalai upto finbalai:
+ if xpart(Xn[k])<MinX:
+ MinX:=xpart(Xn[k]);
+ fi;
+ if xpart(Xn[k])>MaxX:
+ MaxX:=xpart(Xn[k]);
+ fi;
+ if ypart(Xn[k])<MinY:
+ MinY:=ypart(Xn[k]);
+ fi;
+ if ypart(Xn[k])>MaxY:
+ MaxY:=ypart(Xn[k]);
+ fi;
+ endfor;
+ if MaxY<1:
+ MaxY:=2;
+ fi;
+ if MinY>-1:
+ MinY:=-2;
+ fi;
+ if MinY<0:
+ if MinY<>ceiling(MinY):
+ MinY:=ceiling(MinY)-1;
+ fi;
+ fi;
+ if MinX<0:
+ if MinX<>ceiling(MinX):
+ MinX:=ceiling(MinX)-1;
+ fi;
+ fi;
+ if MaxY<>ceiling(MaxY):
+ MaxY:=ceiling(MaxY);
+ fi;
+ if MaxX<>ceiling(MaxX):
+ MaxX:=ceiling(MaxX);
+ fi;
+ if MaxX<1:
+ MaxX:=1;
+ fi;
+ if MaxY<1:
+ MaxY:=1;
+ fi;
+ %
+ path cadreexterieur;
+ cadreexterieur=(((MinX-1)*X.u*cm,(MinY-1)*Y.u*cm)--((MaxX+1)*X.u*cm,(MinY-1)*Y.u*cm)--((MaxX+1)*X.u*cm,(MaxY+1)*Y.u*cm)--((MinX-1)*X.u*cm,(MaxY+1)*Y.u*cm)--cycle);
+ for l=1 upto N-1:
+ draw SplineCubique(xpart(Xn[l]),ypart(Xn[l]),xpart(Xn[l+1]),ypart(Xn[l+1]),ypart(Dn[l]),xpart(Dn[l+1])) withpen pencircle scaled Epaisseur withcolor CoulTrace;
+ endfor;
+ clip currentpicture to cadreexterieur;
+ picture RetiensCourbe;
+ RetiensCourbe=currentpicture;
+ currentpicture:=nullpicture;
+ for k=MinY-1 step y.u until MaxY+1:
+ draw cm*((MinX-1)*X.u,k*Y.u)--cm*((MaxX+1)*X.u,k*Y.u) withcolor 0.75white;
+ endfor;
+ for k=MinX-1 step x.u until MaxX+1:
+ draw cm*(k*X.u,(MinY-1)*Y.u)--cm*(k*X.u,(MaxY+1)*Y.u) withcolor 0.75white;
+ endfor;
+ if PointsCourbe:
+ for k=debutbalai upto finbalai:
+ fill cercles(Fn[k],0.5mm);
+ endfor;
+ fi;
+ drawarrow (0,(MinY-1)*Y.u*cm)--(0,(MaxY+1)*Y.u*cm);
+ drawarrow ((MinX-1)*X.u*cm,0)--((MaxX+1)*X.u*cm,0);
+ %
+ draw RetiensCourbe;
+ label.llft(btex O etex,(0,0));
+ dotlabel.bot(btex 1 etex,cm*X.u*(1,0));
+ dotlabel.lft(btex 1 etex,cm*Y.u*(0,1));
+ if Code:
+ EffectuerTraces;
+ fi;
+ \end{mplibcode}
+ \else
+ \begin{mpost}[mpsettings={\MPSplineCode;}]
+ x.u:=#2;
+ y.u:=#3;
+ X.u:=#4;
+ Y.u:=#5;
+
+ pair Xn[],Fn[],Dn[];%Xn abscisse,ordonnée D : dérivé g,dérivée d
+ n=0;
+ for p_=#1:
+ n:=n+1;
+ if (n mod 2)=1:
+ Xn[(n div 2)+1]=p_;
+ Fn[(n div 2)+1]=cm*(X.u*xpart(p_),Y.u*ypart(p_));
+ else:
+ Dn[(n div 2)]=p_
+ fi;
+ endfor;
+ N:=n div 2;
+ MinX=999;
+ MaxX=-999;
+ MinY=999;
+ MaxY=-999;
+ if Prolonge:
+ debutbalai=2;
+ finbalai=N-1;
+ else:
+ debutbalai=1;
+ finbalai=N;
+ fi;
+ for k=debutbalai upto finbalai:
+ if xpart(Xn[k])<MinX:
+ MinX:=xpart(Xn[k]);
+ fi;
+ if xpart(Xn[k])>MaxX:
+ MaxX:=xpart(Xn[k]);
+ fi;
+ if ypart(Xn[k])<MinY:
+ MinY:=ypart(Xn[k]);
+ fi;
+ if ypart(Xn[k])>MaxY:
+ MaxY:=ypart(Xn[k]);
+ fi;
+ endfor;
+ if MaxY<1:
+ MaxY:=2;
+ fi;
+ if MinY>-1:
+ MinY:=-2;
+ fi;
+ if MinY<0:
+ if MinY<>ceiling(MinY):
+ MinY:=ceiling(MinY)-1;
+ fi;
+ fi;
+ if MinX<0:
+ if MinX<>ceiling(MinX):
+ MinX:=ceiling(MinX)-1;
+ fi;
+ fi;
+ if MaxY<>ceiling(MaxY):
+ MaxY:=ceiling(MaxY);
+ fi;
+ if MaxX<>ceiling(MaxX):
+ MaxX:=ceiling(MaxX);
+ fi;
+ if MaxX<1:
+ MaxX:=1;
+ fi;
+ if MaxY<1:
+ MaxY:=1;
+ fi;
+ %
+ path cadreexterieur;
+ cadreexterieur=(((MinX-1)*X.u*cm,(MinY-1)*Y.u*cm)--((MaxX+1)*X.u*cm,(MinY-1)*Y.u*cm)--((MaxX+1)*X.u*cm,(MaxY+1)*Y.u*cm)--((MinX-1)*X.u*cm,(MaxY+1)*Y.u*cm)--cycle);
+ for l=1 upto N-1:
+ draw SplineCubique(xpart(Xn[l]),ypart(Xn[l]),xpart(Xn[l+1]),ypart(Xn[l+1]),ypart(Dn[l]),xpart(Dn[l+1])) withpen pencircle scaled Epaisseur withcolor CoulTrace;
+ endfor;
+ clip currentpicture to cadreexterieur;
+ picture RetiensCourbe;
+ RetiensCourbe=currentpicture;
+ currentpicture:=nullpicture;
+ for k=MinY-1 step y.u until MaxY+1:
+ draw cm*((MinX-1)*X.u,k*Y.u)--cm*((MaxX+1)*X.u,k*Y.u) withcolor 0.75white;
+ endfor;
+ for k=MinX-1 step x.u until MaxX+1:
+ draw cm*(k*X.u,(MinY-1)*Y.u)--cm*(k*X.u,(MaxY+1)*Y.u) withcolor 0.75white;
+ endfor;
+ if PointsCourbe:
+ for k=debutbalai upto finbalai:
+ fill cercles(Fn[k],0.5mm);
+ endfor;
+ fi;
+ drawarrow (0,(MinY-1)*Y.u*cm)--(0,(MaxY+1)*Y.u*cm);
+ drawarrow ((MinX-1)*X.u*cm,0)--((MaxX+1)*X.u*cm,0);
+ %
+ draw RetiensCourbe;
+ label.llft(btex O etex,(0,0));
+ dotlabel.bot(btex 1 etex,cm*X.u*(1,0));
+ dotlabel.lft(btex 1 etex,cm*Y.u*(0,1));
+ if Code:
+ EffectuerTraces;
+ fi;
+ \end{mpost}
+ \fi
+}
+
\def\PfCTraceMGCode{%
nbcourbe=\ListeDesFonctionslen;
%