| 1 |
% tkz-grapheur-macros.tex |
| 2 |
% Copyright 2026 Cédric Pierquet |
| 3 |
% Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt |
| 4 |
% macros [int] de tkz-grapheur-fr |
| 5 |
|
| 6 |
%====PATCH SIMPLEKV |
| 7 |
% synchronisation booléen FR↔EN (défaut false côté FR) |
| 8 |
\newcommand\tkzgrphSetKVboolFalse[3][]{% |
| 9 |
% #1=famille #2=clé EN #3=clé FR |
| 10 |
\ifboolKV[#1]{#2}{\setKV[#1]{#3=true}}{}% |
| 11 |
} |
| 12 |
|
| 13 |
% synchronisation booléen FR↔EN (défaut true côté FR) |
| 14 |
\newcommand\tkzgrphSetKVboolTrue[3][]{% |
| 15 |
% #1=famille #2=clé EN #3=clé FR |
| 16 |
\ifboolKV[#1]{#2}{}{\setKV[#1]{#3=false}}% |
| 17 |
} |
| 18 |
|
| 19 |
%====CONSTANTE PI pour xint, à voir si incompatibilité... |
| 20 |
\xintdefvar pi:=3.141592653589793238462643; |
| 21 |
\xintdeffloatvar pi:=3.141592653589793238462643; |
| 22 |
|
| 23 |
%====focntion ln, en langage xint |
| 24 |
\xintdeffunc ln(x) := log(x); |
| 25 |
\xintdeffloatfunc ln(x) := log(x); |
| 26 |
|
| 27 |
%====DENSITÉ KHIDEUX |
| 28 |
\xintdeffloatfunc pflrecigamma(x) := x+0.577215664901*x^2-0.65587807152056*x^3-0.042002635033944*x^4+0.16653861138228*x^5-0.042197734555571*x^6; |
| 29 |
\xintdeffloatfunc pflgamma(x) := (x==1)?{1}{(abs(x)<=0.5)?{1/pflrecigamma(x)}{(x-1)*pflgamma(x-1)}}; |
| 30 |
\xintdeffloatfunc pflkhideux(x,k) := (x<0)?{0}{(1/(2^(k/2)*pflgamma(k/2)))*x^(k/2-1)*exp(-x/2)}; |
| 31 |
|
| 32 |
%====PGFPLOTS MACROS (EN/FR) |
| 33 |
\NewDocumentCommand\findintersectionspgf{ O{ITSC} m m D<>{\myt} }{% |
| 34 |
%1 = name of node name |
| 35 |
%2 = 1st object |
| 36 |
%3 = 2d object |
| 37 |
%4 = macro storing number of intersections |
| 38 |
\path[name intersections={of=#2 and #3,name=#1,total=\t}] \pgfextra{\xdef#4{\t}} ; |
| 39 |
} |
| 40 |
|
| 41 |
\NewDocumentCommand\gextractxnodepgf{ m O{\myxcoord} }{% |
| 42 |
\path \pgfextra{\pgfplotspointgetcoordinates{#1}\pgfkeysgetvalue{/data point/x}{\tmpxgetvalue}\xdef#2{\tmpxgetvalue}} ; |
| 43 |
} |
| 44 |
|
| 45 |
\NewDocumentCommand\gextractynodepgf{ m O{\myycoord} }{% |
| 46 |
\path \pgfextra{\pgfplotspointgetcoordinates{#1}\pgfkeysgetvalue{/data point/y}{\tmpygetvalue}\xdef#2{\tmpygetvalue}} ; |
| 47 |
} |
| 48 |
|
| 49 |
\NewDocumentCommand\gextractxynodepgf{ m O{\myxcoord} O{\myycoord} }{% |
| 50 |
\path \pgfextra{\pgfplotspointgetcoordinates{#1}\pgfkeysgetvalue{/data point/x}{\tmpxgetvalue}\xdef#2{\tmpxgetvalue}\pgfkeysgetvalue{/data point/y}{\tmpygetvalue}\xdef#3{\tmpygetvalue}} ; |
| 51 |
} |
| 52 |
|
| 53 |
\NewDocumentCommand\fillbetweencurvespgf{ O{gray,fill opacity=0.25} m m D<>{} }{% |
| 54 |
\addplot[#1] fill between [of=#2 and #3,soft clip={#4}]; |
| 55 |
} |
| 56 |
|
| 57 |
\NewDocumentCommand\gensplinecubicpgf{ s m m O{\monspline} }{% |
| 58 |
%1=liste |
| 59 |
\setsepchar[.]{§./}% |
| 60 |
\readlist*\SPLlistepoints{#2}% |
| 61 |
%les données |
| 62 |
\def\tmpsplinenumdeb{1} |
| 63 |
\def\tmpsplinenumfin{\SPLlistepointslen}% |
| 64 |
\pflextractcoeff{#3}{\tmpsplinenumdeb}% |
| 65 |
%nb de calculs |
| 66 |
\def\SPLnbsplines{\inteval{\tmpsplinenumfin-1}}% |
| 67 |
%extraction des coordonnées |
| 68 |
\itemtomacro\SPLlistepoints[\tmpsplinenumdeb,1]\xa% |
| 69 |
\itemtomacro\SPLlistepoints[\tmpsplinenumdeb,2]\ya% |
| 70 |
\itemtomacro\SPLlistepoints[\tmpsplinenumdeb,3]\fprimea% |
| 71 |
\itemtomacro\SPLlistepoints[\tmpsplinenumdeb,1]\xb% |
| 72 |
\itemtomacro\SPLlistepoints[\tmpsplinenumdeb,2]\yb% |
| 73 |
\itemtomacro\SPLlistepoints[\tmpsplinenumdeb,3]\fprimeb% |
| 74 |
\IfBooleanTF{#1}% |
| 75 |
{% |
| 76 |
\xdef\tmpcontrolsxa{\xintfloateval{(\xa)+((\xb)-(\xa))/\COEFFA}}% |
| 77 |
\xdef\tmpcontrolsya{\xintfloateval{(\ya)+(\fprimea)*((\xb)-(\xa))/\COEFFA}}% |
| 78 |
\xdef\tmpcontrolsxb{\xintfloateval{(\xb)-((\xb)-(\xa))/\COEFFA}}% |
| 79 |
\xdef\tmpcontrolsyb{\xintfloateval{(\yb)-(\fprimeb)*((\xb)-(\xa))/\COEFFA}}% |
| 80 |
}% |
| 81 |
{% |
| 82 |
\xdef\tmpcontrolsxa{\xintfloateval{(\xa)+cos(atand(\fprimea))*(\xb-(\xa))/\COEFFA}}% |
| 83 |
\xdef\tmpcontrolsya{\xintfloateval{(\ya)+sin(atand(\fprimea))*(\xb-(\xa))/\COEFFA}}% |
| 84 |
\xdef\tmpcontrolsxb{\xintfloateval{(\xb)-cos(atand(\fprimeb))*(\xb-(\xa))/\COEFFA}}% |
| 85 |
\xdef\tmpcontrolsyb{\xintfloateval{(\yb)-sin(atand(\fprimeb))*(\xb-(\xa))/\COEFFA}}% |
| 86 |
}% |
| 87 |
\xdef#4{(\xa,\ya) ..controls (\tmpcontrolsxa,\tmpcontrolsya) and (\tmpcontrolsxb,\tmpcontrolsyb).. (\xb,\yb)}% |
| 88 |
\foreach \i in {\tmpsplinenumdeb,...,\SPLnbsplines}{% |
| 89 |
%extraction des coeffs de compensation |
| 90 |
\pflextractcoeff{#3}{\i}% |
| 91 |
\def\j{\inteval{\i+1}}% |
| 92 |
\itemtomacro\SPLlistepoints[\i,1]\xa% |
| 93 |
\itemtomacro\SPLlistepoints[\i,2]\ya% |
| 94 |
\itemtomacro\SPLlistepoints[\i,3]\fprimea% |
| 95 |
\itemtomacro\SPLlistepoints[\j,1]\xb% |
| 96 |
\itemtomacro\SPLlistepoints[\j,2]\yb% |
| 97 |
\itemtomacro\SPLlistepoints[\j,3]\fprimeb% |
| 98 |
\IfBooleanTF{#1}% |
| 99 |
{% |
| 100 |
\xdef\tmpcontrolsxa{\xintfloateval{(\xa)+(\xb-(\xa))/\COEFFA}}% |
| 101 |
\xdef\tmpcontrolsya{\xintfloateval{(\ya)+(\fprimea)*(\xb-(\xa))/\COEFFA}}% |
| 102 |
\xdef\tmpcontrolsxb{\xintfloateval{(\xb)-(\xb-(\xa))/\COEFFA}}% |
| 103 |
\xdef\tmpcontrolsyb{\xintfloateval{(\yb)-(\fprimeb)*(\xb-(\xa))/\COEFFA}}% |
| 104 |
}% |
| 105 |
{% |
| 106 |
\xdef\tmpcontrolsxa{\xintfloateval{(\xa)+cos(atand(\fprimea))*(\xb-(\xa))/\COEFFA}}% |
| 107 |
\xdef\tmpcontrolsya{\xintfloateval{(\ya)+sin(atand(\fprimea))*(\xb-(\xa))/\COEFFA}}% |
| 108 |
\xdef\tmpcontrolsxb{\xintfloateval{(\xb)-cos(atand(\fprimeb))*(\xb-(\xa))/\COEFFA}}% |
| 109 |
\xdef\tmpcontrolsyb{\xintfloateval{(\yb)-sin(atand(\fprimeb))*(\xb-(\xa))/\COEFFA}}% |
| 110 |
}% |
| 111 |
\xdef#4{#4 ..controls (\tmpcontrolsxa,\tmpcontrolsya) and (\tmpcontrolsxb,\tmpcontrolsyb).. (\xb,\yb)}% |
| 112 |
}% |
| 113 |
} |
| 114 |
|
| 115 |
\NewDocumentCommand\addplotspline{ s O{} D<>{3} m O{\monspline} }{% |
| 116 |
\IfBooleanTF{#1}% |
| 117 |
{% |
| 118 |
\gensplinecubicpgf*{#4}{#3}[#5]% |
| 119 |
}% |
| 120 |
{% |
| 121 |
\gensplinecubicpgf{#4}{#3}[#5]% |
| 122 |
}% |
| 123 |
\draw[#2] #5 ; |
| 124 |
} |
| 125 |
|
| 126 |
%====MACRO INTERNE : transformation d'une liste interpo (x1,y1)(x2,y2)... liste reconstruite est stockée dans \TRFlistedecaleeinterpo |
| 127 |
\NewDocumentCommand\tkzg@transfo@interpo{ m m m }{% |
| 128 |
%#1=liste interpo originale, #2=a, #3=b |
| 129 |
%retrait de la première '(' et de la dernière ')' |
| 130 |
\StrGobbleLeft{#1}{1}[\TRFtmpinterpo]% |
| 131 |
\StrGobbleRight{\TRFtmpinterpo}{1}[\TRFtmpinterpo]% |
| 132 |
\setsepchar{)(}% |
| 133 |
\readlist*\TRFlisteinterpo{\TRFtmpinterpo}% |
| 134 |
\gdef\TRFlistedecaleeinterpo{}% |
| 135 |
\foreach \i in {1,...,\TRFlisteinterpolen}{% |
| 136 |
\StrCut{\TRFlisteinterpo[\i]}{,}{\TRFxi}{\TRFyi}% |
| 137 |
\xdef\TRFxip{\xintfloateval{(\TRFxi)+(#2)}}% |
| 138 |
\xdef\TRFyip{\xintfloateval{(\TRFyi)+(#3)}}% |
| 139 |
\xdef\TRFlistedecaleeinterpo{\TRFlistedecaleeinterpo(\TRFxip,\TRFyip)}% |
| 140 |
}% |
| 141 |
} |
| 142 |
|
| 143 |
%====MACRO INTERNE : transformation d'une liste spline x/y/d § x/y/d §... liste reconstruite est stockée dans \TRFlistedecaleespline |
| 144 |
% NB : pas de § final (cohérent avec le format attendu par \GenererSpline) |
| 145 |
\NewDocumentCommand\tkzg@transfo@spline{ m m m }{% |
| 146 |
%#1=liste spline originale, #2=a, #3=b |
| 147 |
\setsepchar[.]{§./}% |
| 148 |
\readlist*\TRFlistepoints{#1}% |
| 149 |
\gdef\TRFlistedecaleespline{}% |
| 150 |
\foreach \i in {1,...,\TRFlistepointslen}{% |
| 151 |
\itemtomacro\TRFlistepoints[\i,1]\TRFxi% |
| 152 |
\itemtomacro\TRFlistepoints[\i,2]\TRFyi% |
| 153 |
\itemtomacro\TRFlistepoints[\i,3]\TRFdi% |
| 154 |
% x' = xi+a, y' = yi+b, d' = di (pente inchangée par translation) |
| 155 |
\xdef\TRFxip{\xintfloateval{(\TRFxi)+(#2)}}% |
| 156 |
\xdef\TRFyip{\xintfloateval{(\TRFyi)+(#3)}}% |
| 157 |
% § entre les points, mais pas après le dernier |
| 158 |
\ifnum\i=\TRFlistepointslen% |
| 159 |
\xdef\TRFlistedecaleespline{\TRFlistedecaleespline\TRFxip/\TRFyip/\TRFdi}% |
| 160 |
\else% |
| 161 |
\xdef\TRFlistedecaleespline{\TRFlistedecaleespline\TRFxip/\TRFyip/\TRFdi §}% |
| 162 |
\fi% |
| 163 |
}% |
| 164 |
} |
| 165 |
|
| 166 |
%====MACRO INTERNE : réflexion d'une liste interpo (x1,y1)(x2,y2)... |
| 167 |
% stocke le résultat dans \RFXlistedecaleeinterpo |
| 168 |
\NewDocumentCommand\tkzg@reflexion@interpo{ m m }{% |
| 169 |
%#1=liste interpo originale, #2=axe (x/y/yx) |
| 170 |
\StrGobbleLeft{#1}{1}[\RFXtmpinterpo]% |
| 171 |
\StrGobbleRight{\RFXtmpinterpo}{1}[\RFXtmpinterpo]% |
| 172 |
\setsepchar{)(}% |
| 173 |
\readlist*\RFXlisteinterpo{\RFXtmpinterpo}% |
| 174 |
\gdef\RFXlistedecaleeinterpo{}% |
| 175 |
\foreach \i in {1,...,\RFXlisteinterpolen}{% |
| 176 |
\StrCut{\RFXlisteinterpo[\i]}{,}{\RFXxi}{\RFXyi}% |
| 177 |
\IfStrEqCase{#2}{% |
| 178 |
{x}{% |
| 179 |
% -f(x) : (xi, -yi) |
| 180 |
\xdef\RFXxip{\xintfloateval{(\RFXxi)}}% |
| 181 |
\xdef\RFXyip{\xintfloateval{-(\RFXyi)}}% |
| 182 |
}% |
| 183 |
{y}{% |
| 184 |
% f(-x) : (-xi, yi) |
| 185 |
\xdef\RFXxip{\xintfloateval{-(\RFXxi)}}% |
| 186 |
\xdef\RFXyip{\xintfloateval{(\RFXyi)}}% |
| 187 |
}% |
| 188 |
{yx}{% |
| 189 |
% réciproque : (yi, xi) |
| 190 |
\xdef\RFXxip{\xintfloateval{(\RFXyi)}}% |
| 191 |
\xdef\RFXyip{\xintfloateval{(\RFXxi)}}% |
| 192 |
}% |
| 193 |
}% |
| 194 |
\xdef\RFXlistedecaleeinterpo{\RFXlistedecaleeinterpo(\RFXxip,\RFXyip)}% |
| 195 |
}% |
| 196 |
} |
| 197 |
|
| 198 |
%====MACRO INTERNE : réflexion d'une liste spline x/y/d § x/y/d §... résultat dans \RFXlistedecaleespline |
| 199 |
\NewDocumentCommand\tkzg@reflexion@spline{ m m }{% |
| 200 |
%#1=liste spline originale, #2=axe (x/y/yx) |
| 201 |
\setsepchar[.]{§./}% |
| 202 |
\readlist*\RFXlistepoints{#1}% |
| 203 |
\gdef\RFXlistedecaleespline{}% |
| 204 |
% Détermination du sens de parcours : |
| 205 |
% Axe=x : abscisses xi inchangées → ordre naturel |
| 206 |
% Axe=y : nouvelles abscisses = -xi → ordre inversé si xi croissants |
| 207 |
% Axe=yx : scope avec matrix transform |
| 208 |
\IfStrEqCase{#2}{% |
| 209 |
{x}{\edef\RFXboucle{1,...,\RFXlistepointslen}\edef\RFXdernierindex{\RFXlistepointslen}}% |
| 210 |
{y}{% |
| 211 |
% nouvelles abscisses = -xi : si xi croissants → -xi décroissants → inverser |
| 212 |
\itemtomacro\RFXlistepoints[1,1]\RFXxpremier% |
| 213 |
\itemtomacro\RFXlistepoints[\RFXlistepointslen,1]\RFXxdernier% |
| 214 |
\xintifboolexpr{(\RFXxpremier) < (\RFXxdernier)}% |
| 215 |
{\edef\RFXboucle{\RFXlistepointslen,...,1}\def\RFXdernierindex{1}}% |
| 216 |
{\edef\RFXboucle{1,...,\RFXlistepointslen}\edef\RFXdernierindex{\RFXlistepointslen}}% |
| 217 |
}% |
| 218 |
}% |
| 219 |
\foreach \i in \RFXboucle{% |
| 220 |
\itemtomacro\RFXlistepoints[\i,1]\RFXxi% |
| 221 |
\itemtomacro\RFXlistepoints[\i,2]\RFXyi% |
| 222 |
\itemtomacro\RFXlistepoints[\i,3]\RFXdi% |
| 223 |
\IfStrEqCase{#2}{% |
| 224 |
{x}{% |
| 225 |
% -f(x) : (xi, -yi, -di) |
| 226 |
\xdef\RFXxip{\xintfloateval{(\RFXxi)}}% |
| 227 |
\xdef\RFXyip{\xintfloateval{-(\RFXyi)}}% |
| 228 |
\xdef\RFXdip{\xintfloateval{-(\RFXdi)}}% |
| 229 |
}% |
| 230 |
{y}{% |
| 231 |
% f(-x) : (-xi, yi, -di) |
| 232 |
\xdef\RFXxip{\xintfloateval{-(\RFXxi)}}% |
| 233 |
\xdef\RFXyip{\xintfloateval{(\RFXyi)}}% |
| 234 |
\xdef\RFXdip{\xintfloateval{-(\RFXdi)}}% |
| 235 |
}% |
| 236 |
}% |
| 237 |
% § entre les points, mais pas après le dernier |
| 238 |
\ifnum\i=\RFXdernierindex\relax% |
| 239 |
\xdef\RFXlistedecaleespline{\RFXlistedecaleespline\RFXxip/\RFXyip/\RFXdip}% |
| 240 |
\else% |
| 241 |
\xdef\RFXlistedecaleespline{\RFXlistedecaleespline\RFXxip/\RFXyip/\RFXdip §}% |
| 242 |
\fi% |
| 243 |
}% |
| 244 |
} |
| 245 |
|
| 246 |
%====Macro auxiliaire : récupère l'élément i (cyclique) d'une liste listofitems |
| 247 |
\newcommand\tkzgmod[3][\tkzgmodres]{% |
| 248 |
\xdef#1{\fpeval{trunc(#2 - (#3)*trunc((#2)/(#3),0), 0)}}% |
| 249 |
\ifnum#1<0\relax% |
| 250 |
\xdef#1{\inteval{#1 + (#3)}}% |
| 251 |
\fi% |
| 252 |
} |
| 253 |
\NewDocumentCommand\itemcycltomacro{ m O{1} m }{% |
| 254 |
\xdef\tmpargcycllist{\fpeval{round(#2,0)}}% |
| 255 |
\ifnum\tmpargcycllist=0\relax% |
| 256 |
\def#3{}% |
| 257 |
\PackageWarning{tkz-grapheur}{itemcycltomacro .: index 0 not available :.}% |
| 258 |
\else% |
| 259 |
\ifnum\tmpargcycllist>0\relax% |
| 260 |
\tkzgmod{#2-1}{\csname\expandafter\@gobble\string#1len\endcsname}% |
| 261 |
\else% |
| 262 |
\tkzgmod{#2}{\csname\expandafter\@gobble\string#1len\endcsname}% |
| 263 |
\fi% |
| 264 |
\xdef\pfltmpidx{\inteval{\tkzgmodres+1}}% |
| 265 |
\itemtomacro#1[\pfltmpidx]{#3}% |
| 266 |
\fi% |
| 267 |
} |
| 268 |
|
| 269 |
%====MACRO INTERNE : calcul de f^(k)(a) par différences finies centrées |
| 270 |
% résultat stocké dans \pfltaylorderivk |
| 271 |
% #1 = nom de la fonction xint |
| 272 |
% #2 = ordre k |
| 273 |
% #3 = point a |
| 274 |
% #4 = pas h |
| 275 |
\NewDocumentCommand\tkzg@taylor@derive{ m m m m }{% |
| 276 |
\xdef\pfltaylorderivk{% |
| 277 |
\xintfloateval{% |
| 278 |
add( |
| 279 |
(-1)^(j) * binomial(#2,j) * #1((#3) + ((#2)/2 - j)*(#4)), |
| 280 |
j=0..#2 |
| 281 |
) / (#4)^(#2) |
| 282 |
}% |
| 283 |
}% |
| 284 |
} |
| 285 |
|
| 286 |
%====MACRO INTERNE : construction de la fonction Taylor d'ordre N |
| 287 |
% définit pfltaylorpoly(x) comme fonction xint |
| 288 |
% #1 = nom de la fonction xint |
| 289 |
% #2 = ordre N |
| 290 |
% #3 = point a |
| 291 |
% #4 = pas h |
| 292 |
\NewDocumentCommand\tkzg@taylor@build{ m m m m }{% |
| 293 |
% calcul des coefficients c_k = f^(k)(a) / k! |
| 294 |
% et construction de la somme |
| 295 |
\gdef\pfltaylorexpr{0}% |
| 296 |
\foreach \k in {0,...,#2}{% |
| 297 |
\tkzg@taylor@derive{#1}{\k}{#3}{#4}% |
| 298 |
% terme k : c_k * (x-a)^k |
| 299 |
\xdef\pfltaylorexpr{% |
| 300 |
\pfltaylorexpr + \pfltaylorderivk / factorial (\k) * (x-(#3))^\k% |
| 301 |
}% |
| 302 |
}% |
| 303 |
\xintdeffloatfunc pfltaylorpoly(x) := \pfltaylorexpr ;% |
| 304 |
} |
| 305 |
|
| 306 |
\endinput |