| 1 |
% Author : C. Pierquet |
| 2 |
% licence : Released under the LaTeX Project Public License v1.3c |
| 3 |
% or later, see http://www.latex-project.org/lppl.txtf |
| 4 |
|
| 5 |
\NeedsTeXFormat{LaTeX2e} |
| 6 |
\ProvidesPackage{tikz2d-fr}[2023/05/28 0.1.1 Petites aides pour l'utilisation de TikZ 2D] |
| 7 |
%0.1.1 Ajout de [TaillePolice] + Commandes Point(s) par transformations (trans / rotat / sym) |
| 8 |
%0.1.0 Version initiale |
| 9 |
|
| 10 |
%------Packages utiles |
| 11 |
\RequirePackage{tikz,pgffor} |
| 12 |
\RequirePackage{xstring} |
| 13 |
\RequirePackage{xintexpr} |
| 14 |
\RequirePackage{simplekv} |
| 15 |
\RequirePackage{listofitems} |
| 16 |
%------Librairies tikz |
| 17 |
\usetikzlibrary{calc} |
| 18 |
\usetikzlibrary{decorations,decorations.pathmorphing} |
| 19 |
|
| 20 |
%------Style main levée (avant dans ProfLycee) |
| 21 |
\tikzset{% |
| 22 |
mainlevee/.style args={#1et#2}{decorate,decoration={random steps,segment length=#1,amplitude=#2}}, |
| 23 |
mainlevee/.default={5mm et 0.6pt} |
| 24 |
} |
| 25 |
|
| 26 |
%------Points |
| 27 |
%%------Commandes internes pour les nœuds et points |
| 28 |
\NewDocumentCommand\TransfPosTikzDD{ m }{%défaut below |
| 29 |
\def\PosTmpLabel{below} |
| 30 |
\IfEq{#1}{b}{\def\PosTmpLabel{below}}{} |
| 31 |
\IfEq{#1}{d}{\def\PosTmpLabel{right}}{} |
| 32 |
\IfEq{#1}{h}{\def\PosTmpLabel{above}}{} |
| 33 |
\IfEq{#1}{g}{\def\PosTmpLabel{left}}{} |
| 34 |
\IfEq{#1}{bg}{\def\PosTmpLabel{below left}}{} |
| 35 |
\IfEq{#1}{bd}{\def\PosTmpLabel{below right}}{} |
| 36 |
\IfEq{#1}{hg}{\def\PosTmpLabel{above left}}{} |
| 37 |
\IfEq{#1}{hd}{\def\PosTmpLabel{above right}}{} |
| 38 |
} |
| 39 |
\tikzset{pics/croixdd/.style args={#1/#2}{ |
| 40 |
code={ |
| 41 |
\draw[line width={0.4*#1},rotate=#2] (-#1,0) -- (#1,0); |
| 42 |
\draw[line width={0.4*#1},rotate=#2] (0,-#1) -- (0, #1); |
| 43 |
} |
| 44 |
}, |
| 45 |
pics/croixdd/.default={4pt/0} |
| 46 |
} |
| 47 |
|
| 48 |
%%------Créer/Placer/Nommer Point(s) 2d |
| 49 |
\defKV[TkzTwoDimPoint]{% |
| 50 |
PosLabel=\def\TwoDimLabel{#1},% |
| 51 |
DecalLabel=\def\TwoDimDecalLabel{#1},% |
| 52 |
StyleMarque=\def\TwoDimStylePt{#1},% |
| 53 |
TailleMarque=\def\TwoDimtaillePt{#1},% |
| 54 |
Couleur=\def\TwoDimCoul{#1},% |
| 55 |
TaillePolice=\def\TwoDimFonte{#1} |
| 56 |
} |
| 57 |
|
| 58 |
\setKVdefault[TkzTwoDimPoint]{% |
| 59 |
PosLabel={b},% |
| 60 |
DecalLabel=2pt,% |
| 61 |
StyleMarque=o,% |
| 62 |
TailleMarque=2.5pt,% |
| 63 |
Couleur=black,% |
| 64 |
Math=false,% |
| 65 |
TaillePolice=\normalsize |
| 66 |
} |
| 67 |
|
| 68 |
\NewDocumentCommand\DefinirPoint{ s O{} m m D<>{#3} }{% |
| 69 |
%*=label |
| 70 |
%2=clés |
| 71 |
%3=nom nœud |
| 72 |
%4=coordonnées x,y |
| 73 |
%5=label si différent |
| 74 |
\useKVdefault[TkzTwoDimPoint]% |
| 75 |
\setKV[TkzTwoDimPoint]{#2}% |
| 76 |
\TransfPosTikzDD{\TwoDimLabel} |
| 77 |
\coordinate (#3) at (#4) ; |
| 78 |
\IfBooleanTF{#1}%on désactive le label avec (*) |
| 79 |
{}% |
| 80 |
{\draw (#3) node[\TwoDimCoul,\PosTmpLabel=\TwoDimDecalLabel,font=\TwoDimFonte] {\ifboolKV[TkzTwoDimPoint]{Math}{$#5$}{#5}} ;}% |
| 81 |
} |
| 82 |
|
| 83 |
\NewDocumentCommand\DefinirPoints{ s O{} m }{% |
| 84 |
%*=labels off |
| 85 |
%2=clés |
| 86 |
%3=liste nom/coordonnées/pos |
| 87 |
%\useKVdefault[TkzTwoDimPoint]% |
| 88 |
%\setKV[TkzTwoDimPoint]{#2}% |
| 89 |
\setsepchar[.]{ ./}% |
| 90 |
\readlist*\ListePtsPlan{#3} |
| 91 |
\xintifboolexpr{\ListePtsPlanlen == 1}% |
| 92 |
{% |
| 93 |
\IfBooleanTF{#1}%on désactive le label avec (*) |
| 94 |
{% |
| 95 |
\DefinirPoint*[#2]{\ListePtsPlan[1,1]}{\ListePtsPlan[1,2]} |
| 96 |
}% |
| 97 |
{% |
| 98 |
\DefinirPoint[#2,PosLabel={\ListePtsPlan[1,3]}]{\ListePtsPlan[1,1]}{\ListePtsPlan[1,2]} |
| 99 |
}% |
| 100 |
}% |
| 101 |
{% |
| 102 |
\foreach \i in {1,2,...,\ListePtsPlanlen} |
| 103 |
{% |
| 104 |
\IfBooleanTF{#1}%on désactive le label avec (*) |
| 105 |
{% |
| 106 |
\DefinirPoint*[#2]{\ListePtsPlan[\i,1]}{\ListePtsPlan[\i,2]} |
| 107 |
}% |
| 108 |
{% |
| 109 |
\DefinirPoint[#2,PosLabel={\ListePtsPlan[\i,3]}]{\ListePtsPlan[\i,1]}{\ListePtsPlan[\i,2]} |
| 110 |
}% |
| 111 |
}% |
| 112 |
}% |
| 113 |
} |
| 114 |
|
| 115 |
\NewDocumentCommand\MarquerPoint{ O{} m }{% |
| 116 |
%1=clés |
| 117 |
%2=nom nœud |
| 118 |
\useKVdefault[TkzTwoDimPoint]% |
| 119 |
\setKV[TkzTwoDimPoint]{#1}% |
| 120 |
\IfStrEq{\TwoDimStylePt}{o}% |
| 121 |
{\filldraw[\TwoDimCoul] (#2) circle[radius={\TwoDimtaillePt-0.5pt}] ;}{}% |
| 122 |
\IfStrEq{\TwoDimStylePt}{x}% |
| 123 |
{\draw[\TwoDimCoul] (#2) pic{croixdd=\TwoDimtaillePt/45} ;}{}% |
| 124 |
\IfStrEq{\TwoDimStylePt}{+}% |
| 125 |
{\draw[\TwoDimCoul] (#2) pic{croixdd=\TwoDimtaillePt/0} ;}{}% |
| 126 |
} |
| 127 |
|
| 128 |
\NewDocumentCommand\MarquerPoints{ O{} m }{% |
| 129 |
%1=clés |
| 130 |
%2=liste nom/coordonnées/pos |
| 131 |
%\useKVdefault[TkzTwoDimPoint]% |
| 132 |
%\setKV[TkzTwoDimPoint]{#1}% |
| 133 |
\foreach \i in {#2} |
| 134 |
{% |
| 135 |
\MarquerPoint[#1]{\i} |
| 136 |
}% |
| 137 |
} |
| 138 |
|
| 139 |
%------Tracer des segments |
| 140 |
\defKV[TraceSegments]{% |
| 141 |
Cap=\xdef\TracSegCap{#1},% |
| 142 |
Join=\xdef\TracSegJoin{#1},% |
| 143 |
Couleurs=\xdef\TracSegCoul{#1} |
| 144 |
} |
| 145 |
|
| 146 |
\setKVdefault[TraceSegments]{% |
| 147 |
Cap=round,% |
| 148 |
Couleurs=black,% |
| 149 |
Cycle=false,% |
| 150 |
Join=miter,% |
| 151 |
Suite=false |
| 152 |
} |
| 153 |
|
| 154 |
\NewDocumentCommand\TracerSegments{ O{} D<>{thick} m }{% |
| 155 |
\useKVdefault[TraceSegments]% |
| 156 |
\setKV[TraceSegments]{#1}% |
| 157 |
\ifboolKV[TraceSegments]{Suite}%si on enchaîne les points A->B->C, sinon A/B A/C ... |
| 158 |
{% |
| 159 |
\setsepchar{ }% |
| 160 |
\readlist*\LPTSEGM{#3}% |
| 161 |
\IfSubStr{\TracSegCoul}{,}%si ',' := un par un, sinon enchaine |
| 162 |
{% |
| 163 |
\setsepchar{,}% |
| 164 |
\readlist*\LCSEGM{\TracSegCoul}% |
| 165 |
\ifboolKV[TraceSegments]{Cycle}% |
| 166 |
{% |
| 167 |
\foreach \i in {1,2,...,\inteval{\LPTSEGMlen-1}}% |
| 168 |
{% |
| 169 |
\draw[color={\LCSEGM[\i]},line cap={\TracSegCap},#2] (\LPTSEGM[\i]) -- (\LPTSEGM[\inteval{\i+1}]) ; |
| 170 |
}% |
| 171 |
\draw[color={\LCSEGM[-1]},line cap={\TracSegCap},#2] (\LPTSEGM[-1]) -- (\LPTSEGM[1]) ; |
| 172 |
}% |
| 173 |
{% |
| 174 |
\foreach \i in {1,2,...,\inteval{\LPTSEGMlen-1}}% |
| 175 |
{% |
| 176 |
\draw[color={\LCSEGM[\i]},line cap={\TracSegCap},#2] (\LPTSEGM[\i]) -- (\LPTSEGM[\inteval{\i+1}]) ; |
| 177 |
}% |
| 178 |
}% |
| 179 |
}% |
| 180 |
{% |
| 181 |
\StrSubstitute{#3}{ }{)--(}[\tmplstpts]% |
| 182 |
\xdef\tmplstptsconv{(\tmplstpts)}% |
| 183 |
\ifboolKV[TraceSegments]{Cycle}% |
| 184 |
{% |
| 185 |
\draw[color={\TracSegCoul},line join={\TracSegJoin},#2] \tmplstptsconv--cycle ; |
| 186 |
}% |
| 187 |
{% |
| 188 |
\draw[color={\TracSegCoul},line join={\TracSegJoin},#2] \tmplstptsconv ; |
| 189 |
}% |
| 190 |
}% |
| 191 |
}% |
| 192 |
{% |
| 193 |
\setsepchar[.]{ ./}% |
| 194 |
\readlist*\LPTSEGM{#3}% |
| 195 |
\IfSubStr{\TracSegCoul}{,}%si ',' := un par un, sinon enchaine |
| 196 |
{% |
| 197 |
\setsepchar{,} |
| 198 |
\readlist*\LCSEGM{\TracSegCoul}% |
| 199 |
\xintifboolexpr{\LPTSEGMlen == 1}% |
| 200 |
{% |
| 201 |
\draw[color={\LCSEGM[1]},line cap={\TracSegCap},#2] (\LPTSEGM[1,1]) -- (\LPTSEGM[1,2]) ; |
| 202 |
}% |
| 203 |
{% |
| 204 |
\foreach \i in {1,2,...,\LPTSEGMlen}% |
| 205 |
{% |
| 206 |
\draw[color={\LCSEGM[\i]},line cap={\TracSegCap},#2] (\LPTSEGM[\i,1]) -- (\LPTSEGM[\i,2]) ; |
| 207 |
}% |
| 208 |
}% |
| 209 |
|
| 210 |
}% |
| 211 |
{% |
| 212 |
\xintifboolexpr{\LPTSEGMlen == 1}% |
| 213 |
{% |
| 214 |
\draw[color={\TracSegCoul},line cap={\TracSegCap},#2] (\LPTSEGM[1,1]) -- (\LPTSEGM[1,2]) ; |
| 215 |
}% |
| 216 |
{% |
| 217 |
\foreach \i in {1,2,...,\LPTSEGMlen}% |
| 218 |
{% |
| 219 |
\draw[color={\TracSegCoul},line cap={\TracSegCap},#2] (\LPTSEGM[\i,1]) -- (\LPTSEGM[\i,2]) ; |
| 220 |
}% |
| 221 |
}% |
| 222 |
}% |
| 223 |
}% |
| 224 |
} |
| 225 |
|
| 226 |
%------Définir des points par transformations |
| 227 |
\NewDocumentCommand\ImagePoint{ s O{} m D<>{\tmpptdef} }{% |
| 228 |
\useKVdefault[TkzTwoDimPoint]% |
| 229 |
\setKV[TkzTwoDimPoint]{#2}% |
| 230 |
%si c'est un translation |
| 231 |
\IfSubStr{#3}{t(}% |
| 232 |
{% |
| 233 |
\StrBefore{#3}{=}[\tmpptdef]% |
| 234 |
\StrBetween{#3}{=}{+}[\tmpptdeb]% |
| 235 |
\IfSubStr{#3}{,}% |
| 236 |
{% |
| 237 |
\StrBetween{#3}{t(}{,}[\tmpk]% |
| 238 |
\StrBetween{#3}{,}{>}[\tmpvecdeb]% |
| 239 |
\StrBetween{#3}{>}{)}[\tmpvecfin]% |
| 240 |
}% |
| 241 |
{% |
| 242 |
\xdef\tmpk{1}% |
| 243 |
\StrBetween{#3}{t(}{>}[\tmpvecdeb]% |
| 244 |
}% |
| 245 |
\StrBetween{#3}{>}{)}[\tmpvecfin]% |
| 246 |
\TransfPosTikzDD{\TwoDimLabel}% |
| 247 |
\coordinate (\tmpptdef) at ($(\tmpptdeb) + \tmpk*(\tmpvecfin) - \tmpk*(\tmpvecdeb)$) ; |
| 248 |
}{}% |
| 249 |
%si c'est une rotation |
| 250 |
\IfSubStr{#3}{r(}% |
| 251 |
{% |
| 252 |
\StrBefore{#3}{=}[\tmpptdef]% |
| 253 |
\StrBetween{#3}{=}{+}[\tmpptdeb]% |
| 254 |
\StrBetween{#3}{r(}{,}[\tmpptcenter]% |
| 255 |
\StrBetween{#3}{,}{)}[\tmpangle]% |
| 256 |
\TransfPosTikzDD{\TwoDimLabel}% |
| 257 |
\coordinate (\tmpptdef) at ([rotate around={\tmpangle:(\tmpptcenter)}]\tmpptdeb); |
| 258 |
}{}% |
| 259 |
%si c'est une symetrie |
| 260 |
\IfSubStr{#3}{s(}% |
| 261 |
{% |
| 262 |
\StrBefore{#3}{=}[\tmpptdef]% |
| 263 |
\StrBetween{#3}{=}{+}[\tmpptdeb]% |
| 264 |
\StrBetween{#3}{s(}{)}[\tmpptcenter]% |
| 265 |
\TransfPosTikzDD{\TwoDimLabel}% |
| 266 |
\coordinate (\tmpptdef) at ([rotate around={180:(\tmpptcenter)}]\tmpptdeb); |
| 267 |
}% |
| 268 |
{}% |
| 269 |
\IfBooleanTF{#1}%on désactive le label avec (*) |
| 270 |
{}% |
| 271 |
{\draw (\tmpptdef) node[\TwoDimCoul,\PosTmpLabel=\TwoDimDecalLabel,font=\TwoDimFonte] {\ifboolKV[TkzTwoDimPoint]{Math}{$#4$}{#4}} ;}% |
| 272 |
} |
| 273 |
|
| 274 |
\NewDocumentCommand\ImagesPoints{ s O{} m }{% |
| 275 |
\useKVdefault[TkzTwoDimPoint]% |
| 276 |
\setKV[TkzTwoDimPoint]{#2}% |
| 277 |
\setsepchar{§}% |
| 278 |
\readlist*\listetmptransf{#3}% |
| 279 |
\foreachitem \formule \in \listetmptransf{% |
| 280 |
\IfBooleanTF{#1}% |
| 281 |
{% |
| 282 |
\ImagePoint*[#2]{\formule}% |
| 283 |
}% |
| 284 |
{% |
| 285 |
\ImagePoint[#2]{\formule}% |
| 286 |
}% |
| 287 |
}% |
| 288 |
} |
| 289 |
|
| 290 |
\endinput |