summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tkz/tkz-euclide/latex/tkz-obj-eu-arcs.tex
blob: c8ef72c3e6f6c2e035ecc8de925e658ff6a542dd (plain)
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
% tkz-obj-eu-arcs.tex
% Copyright 2020 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{3.02c}
\def\filedate{2020/01/24} 
\typeout{2020/01/24 3.02c  tkz-obj-eu-arcs.tex}  
\makeatletter
%<------------------------------  Arcs -------------------------------------–
% options : delta 
% \def\tkz@delta{0}
% \tikzset{arc style/.style={#1}}
% \pgfkeys{/tikz/.cd,delta/.code={\def\tkz@delta{#1}}}

\gdef\tkz@numa{0}
\pgfkeys{/tkzdrawarc/.cd,
			type/.is choice,
			type/towards/.code               = \def\tkz@numa{0},
			type/rotate/.code                = \def\tkz@numa{1},
			type/angles/.code                = \def\tkz@numa{2}, 
			type/R/.code                     = \def\tkz@numa{3},
			type/R with nodes/.code          = \def\tkz@numa{4},
			towards/.style                   = {type=towards},
			rotate/.style                    = {type=rotate},
			R/.style                   		   = {type=R},
			angles/.style                    = {type=angles},
			R with nodes/.style              = {type=R with nodes},
			diameter/.code    				       = {},
			arc/.code          				       = {},
			size/.code       				         = {},
			mark/.code          			       = {},
			mkpos/.code        				       = {},
			mksize/.code       				       = {},
			mkcolor/.code       			       = {},
			type/.default 					         =	towards,
			delta/.store in					         = \tkz@delta,
			delta 							             = 0,
			/tkzdrawarc/.search also   		     = {/tikz}
}  
\def\tkzDrawArc{\pgfutil@ifnextchar[{\tkz@DrawArc}{\tkz@DrawArc[]}}
\def\tkz@DrawArc[#1](#2,#3)(#4){% 
\begingroup    
\pgfqkeys{/tkzdrawarc}{#1} 
\ifcase\tkz@numa%
   \tkzDrawArcTowards[#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
}
%<--------------------------------------------------------------------------–>
%  ARC    nodes        #2 center #3 first point last point #4
% delta un peu plus à chaque extrémité 
% example : \tkzDrawArc(A,B)(C)      
%<--------------------------------------------------------------------------–>
\def\tkzDrawArcTowards{\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 #4 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
}   
%<--------------------------------------------------------------------------–>
% #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,/tkzdrawarc/.cd,#1]%
       (\tkz@FirstAngle:#3) arc (\tkz@FirstAngle:\tkz@SecondAngle:#3);
\endgroup  
}
%<--------------------------------------------------------------------------–>
%    Degree      #2 center #4 - #3 radius from #5 (degree) to #6(degree) 
%<--------------------------------------------------------------------------–>
\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   
}
%<--------------------------------------------------------------------------–>
\makeatother
\endinput