1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
% Copyright 2011 by Alain Matthes
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
\def\fileversion{1.16 c}
\def\filedate{2011/06/01}
%<--------------------------------------------------------------------------–>
%<------------------------------ Arcs -------------------------------------–>
%<--------------------------------------------------------------------------–>
% options : delta
\def\tkz@delta{0}
\tikzset{arc style/.style={#1}}
\pgfkeys{/tikz/.cd,delta/.code={\def\tkz@delta{#1}}}
\global\def\tkz@numa{0}
\pgfkeys{/drawarc/.cd,
towards/.code = {\global\def\tkz@numa{0}},
rotate/.code = {\global\def\tkz@numa{1}},
angles/.code = {\global\def\tkz@numa{2}},
R/.code = {\global\def\tkz@numa{3}},
R with nodes/.code = {\global\def\tkz@numa{4}},
/drawarc/.unknown/.code = {\let\searchname=\pgfkeyscurrentname
\pgfkeysalso{\searchname/.try=#1,
/tikz/\searchname/.retry=#1,%
/pgf/\searchname/.retry=#1}}
}
\def\tkzDrawArc{\pgfutil@ifnextchar[{\tkz@DrawArc}{\tkz@DrawArc[]}}
\def\tkz@DrawArc[#1](#2,#3)(#4){%
\begingroup
\pgfkeys{/drawarc/.cd,towards,delta=0}
\pgfqkeys{/drawarc}{#1}
\ifcase\tkz@numa%
\tkzDrawArcN[#1](#2,#3)(#4)
\or% 1
\tkzDrawArcRotate[#1](#2,#3)(#4)
\or% 2
\tkzDrawArcAngles[#1](#2,#3)(#4)
\or% 3
\tkzDrawArcRAngles[#1](#2,#3)(#4)
\or% 4
\tkzDrawArcR[#1](#2,#3)(#4)
\fi
\endgroup
}
%<--------------------------------------------------------------------------–>
% #1 center #2 radius #4 first angle (degree) #5 second angle (degree)
% angles 0 .. 180 or -180 .. 0
%<--------------------------------------------------------------------------–>
% example : \tkzDrawArc(A,2 cm)(30,90)
\def\tkzDrawArcRAngles{\pgfutil@ifnextchar[{\tkz@DrawArcRAngles}{%
\tkz@DrawArcRAngles[]}}
\def\tkz@DrawArcRAngles[#1](#2,#3)(#4,#5){%
\begingroup
\pgfmathparse{#4}\edef\tkz@FirstAngle{\pgfmathresult}%
\pgfmathparse{#5}\edef\tkz@SecondAngle{\pgfmathresult}%
\pgfmathgreaterthan{\tkz@FirstAngle}{0}
\ifdim\pgfmathresult pt=1 pt\relax%
\pgfmathgreaterthan{\tkz@FirstAngle}{\tkz@SecondAngle}
\ifdim\pgfmathresult pt=1 pt\relax%
\pgfmathsubtract{\tkz@FirstAngle}{360}
\edef\tkz@FirstAngle{\pgfmathresult}%
\fi
\else
\pgfmathgreaterthan{\tkz@FirstAngle}{\tkz@SecondAngle}
\ifdim\pgfmathresult pt=1 pt\relax%
\pgfmathadd{\tkz@SecondAngle}{360}
\edef\tkz@SecondAngle{\pgfmathresult}%
\fi
\fi
\pgfmathsubtract{\tkz@FirstAngle}{\tkz@delta}
\edef\tkz@FirstAngle{\pgfmathresult}%
\pgfmathadd{\tkz@SecondAngle}{\tkz@delta}
\edef\tkz@SecondAngle{\pgfmathresult}
\draw[shift = {(#2)},compass style,/drawarc/.cd,#1]%
(\tkz@FirstAngle:#3) arc (\tkz@FirstAngle:\tkz@SecondAngle:#3);
\endgroup
}
%<--------------------------------------------------------------------------–>
% ARC nodes #2 center #3 first point last point #4
% delta un peu plus à chaque extrémité
% example : \tkzDrawArc(A,B)(C)
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcN{\pgfutil@ifnextchar[{\tkz@DrawArcN}{\tkz@DrawArcN[]}}
\def\tkz@DrawArcN[#1](#2,#3)(#4){%
\begingroup
\tkzCalcLength(#2,#3)\tkzGetLength{tkz@radius}
\tkzFindSlopeAngle(#2,#3)\tkzGetAngle{tkz@FirstAngle}
\tkzFindSlopeAngle(#2,#4)\tkzGetAngle{tkz@SecondAngle}
\tkz@DrawArcRAngles[#1](#2,\tkz@radius pt)(\tkz@FirstAngle,\tkz@SecondAngle)
\endgroup
}
%<--------------------------------------------------------------------------–>
% nodes #2 center #3 first point rotate #3 with Angle
% delta un peu plus à chaque extrémité
% tkzDrawArcRotate(O,A)(60)
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcRotate{\pgfutil@ifnextchar[{\tkz@DrawArcRotate}{%
\tkz@DrawArcRotate[]}}
\def\tkz@DrawArcRotate[#1](#2,#3)(#4){%
\begingroup
\tkzCalcLength(#2,#3)\tkzGetLength{tkz@radius}
\tkzFindSlopeAngle(#2,#3)\tkzGetAngle{tkz@FirstA}
\pgfmathadd{\tkz@FirstA}{#4}
\edef\tkz@SecondA{\pgfmathresult}
\pgfmathgreaterthan{#4}{0}
\ifdim\pgfmathresult pt=1 pt\relax%
\tkz@DrawArcRAngles[#1](#2,\tkz@radius pt)(\tkz@FirstA,\tkz@SecondA)
\else
\tkz@DrawArcRAngles[#1](#2,\tkz@radius pt)(\tkz@SecondA,\tkz@FirstA)
\fi
\endgroup
}
%<--------------------------------------------------------------------------–>
% deux angles
% \tkzDrawArcAngles(O,A)(0,60)
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcAngles{\pgfutil@ifnextchar[{\tkz@DrawArcAngles}{%
\tkz@DrawArcAngles[]}}
\def\tkz@DrawArcAngles[#1](#2,#3)(#4,#5){%
\begingroup
\tkzCalcLength(#2,#3)
\tkz@DrawArcRAngles[#1](#2,\tkzLengthResult pt)(#4,#5)
\endgroup
}
%<--------------------------------------------------------------------------–>
% Degree #2 center #4 - #3 radius from #5 (degree) to #6(degree)
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcRwithNodesAngles{\pgfutil@ifnextchar[{%
\tkz@DrawArcRwithNodesAngles}{%
\tkz@DrawArcRwithNodesAngles[]}} \def\tkz@DrawArcRwithNodesAngles[#1](#2,#3,#4)(#5,#6){%
\begingroup
\tkzCalcLength(#3,#4)
\tkz@DrawArcRAngles[#1](#2,\tkzLengthResult pt)(#5,#6)
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcRwithNodes{\pgfutil@ifnextchar[{\tkz@DrawArcRwithNodes}{%
\tkz@DrawArcRwithNodes[]}}
\def\tkz@DrawArcRwithNodes[#1](#2,#3,#4)(#5,#6){%
\begingroup
\tkzCalcLength(#3,#4)
\tkzFindSlopeAngle(#2,#5)\tkzGetAngle{tkz@FirstAngle}
\tkzFindSlopeAngle(#2,#6)\tkzGetAngle{tkz@SecondAngle}
\tkz@DrawArcRAngles[#1](#2,\tkzLengthResult)%
(\tkz@FirstAngle,\tkz@SecondAngle)
\endgroup
}
%<--------------------------------------------------------------------------–>
% Nodes R #2 center #3 radius en cm from #4(node) to #5(node)
% \tkzDrawArcR(O,2 cm)(A,B)
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcR{\pgfutil@ifnextchar[{\tkz@DrawArcR}{\tkz@DrawArcR[]}}
\def\tkz@DrawArcR[#1](#2,#3)(#4,#5){%
\begingroup
\tkzFindSlopeAngle(#2,#4)\tkzGetAngle{tkz@FirstAngle}
\tkzFindSlopeAngle(#2,#5)\tkzGetAngle{tkz@SecondAngle}
\tkz@DrawArcRAngles[#1](#2,#3)(\tkz@FirstAngle,\tkz@SecondAngle)
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
% Author Alain Matthes
% idea from Y. Combe %<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
% Utilisation du Compas : Compass
%<--------------------------------------------------------------------------–>
% Setup Compass
%<--------------------------------------------------------------------------–>
\pgfkeys{%
setupcompass/.cd,
line width/.code = {\global\edef\tkz@compass@lw{#1}},
color/.code = {\global\edef\tkz@compass@color{#1}},
style/.code = {\global\edef\tkz@compass@style{#1}},
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzSetUpCompass{\pgfutil@ifnextchar[{\tkzActivOff\tkz@SetUpCompass}{%
\tkzActivOff\tkz@SetUpCompass[]}}
%<--------------------------------------------------------------------------–>
\def\tkz@SetUpCompass[#1]{%
\tkzActivOff
\pgfkeys{%
setupcompass/.cd,
line width = \tkz@euc@compasswidth,
color = \tkz@euc@compasscolor,
style = \tkz@euc@compassstyle
}
\pgfqkeys{/setupcompass}{#1}
\tikzset{compass style/.style={color = \tkz@compass@color,
line width = \tkz@compass@lw,
style = \tkz@compass@style
}}
}
%<--------------------------------------------------------------------------–>
% \tkzCompass(A, B)
%
% Marque de compas auto-ajustée en longueur
% #2 center #3 le point
% Par défaut:
% longueur : 1cm, mais avec un maximum d'un angle de 180°
% angle calculé pour la longueur
% style traits pleins
%
% Paramètres (optionnels, gérés par xkeyval)
% length : longueur de l'arc (ignoré si delta est différent de 0)
% delta : angle sous-tendant l'arc
%<--------------------------------------------------------------------------–>
\pgfkeys{
/compass/delta/.code = {\def\tkz@delta{#1}},
/compass/length/.code = {\def\tkz@length{#1}},
/compass/ratio/.code = {\def\tkz@ratio{#1}},
/compass/.unknown/.code = {\let\searchname=\pgfkeyscurrentname
\pgfkeysalso{\searchname/.try=#1,
/tikz/\searchname/.retry=#1}}
}
% \def\tkz@length{2}
% \pgfkeys{/tikz/.cd,length/.code={\def\tkz@length{#1}}}
\def\tkzCompass{\pgfutil@ifnextchar[{\tkz@Compass}{\tkz@Compass[]}}
\def\tkz@Compass[#1](#2,#3){%
\begingroup
\pgfkeys{%
compass/.cd,
length = 0.75,
delta = 0,
ratio = .5
}
\pgfkeys{compass/.cd,#1}
\tkzCalcLength(#2,#3)\tkzGetLength{tkz@tempLen}
\ifnum\tkz@delta=0 %
\pgfmathsetmacro{\tkz@delta}{min(deg(\tkz@length cm/ \tkz@tempLen pt),180)/2}
\fi
\tkzFindSlopeAngle(#2,#3)\tkzGetAngle{tkz@angle}%
\draw[shift ={(#2)},/compass/.cd,compass style,#1]%
(\tkz@angle-\tkz@delta:\tkz@tempLen pt)%
arc (\tkz@angle-\tkz@delta:\tkz@angle+\tkz@delta:\tkz@tempLen pt);
%};
\endgroup}
%<--------------------------------------------------------------------------–>
\def\tkz@multiCompass#1 #2\@nil{%
\protected@edef\tkz@temp{
\noexpand \tkzCompass[\tkz@optcompass](#1)}\tkz@temp%
\def\tkz@nextArg{#2}%
\ifx\tkzutil@empty\tkz@nextArg
\let\next\@gobble
\fi
\next#2\@nil
}
\def\tkzCompasss{\pgfutil@ifnextchar[{\tkz@Compasss}{\tkz@Compasss[]}}
\def\tkz@Compasss[#1](#2){%
\global\edef\tkz@optcompass{#1}
\begingroup
\let\next\tkz@multiCompass
\next#2 \@nil %
\endgroup
}%
%<--------------------------------------------------------------------------–>
% fin de \tkzCompass
%<--------------------------------------------------------------------------–>\endinput
|