summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tkz-euclide/tkz-tools-intersections.tex
blob: 94c65930a4131ff8c961595325b63f54a6b0baa8 (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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
% 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}   

%<--------------------------------------------------------------------------–>
%                 intersection  de deux lignes
%<--------------------------------------------------------------------------–>
\def\tkzInterLL(#1,#2)(#3,#4){% méthode avec FP
\tkz@InterLL(#1,#2)(#3,#4){tkzPointResult}
}
% méthode with tikz
\def\tkz@InterLL(#1,#2)(#3,#4)#5{%
%\path (intersection of #1--#2 and #3--#4) coordinate(#5);%
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}} 
\tkz@ax\pgf@x %
\tkz@ay\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#2}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#2}{center}} 
\tkz@bx\pgf@x %
\tkz@by\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#3}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#3}{center}} 
\tkz@cx\pgf@x %
\tkz@cy\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#4}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#4}{center}} 
\tkz@dx\pgf@x %
\tkz@dy\pgf@y %
\FPeval\tkz@deltax{\pgf@sys@tonumber{\tkz@ax}-\pgf@sys@tonumber{\tkz@bx}}
\FPdiv\tkz@deltax{\tkz@deltax}{28.45274}
\FPeval\tkz@deltaxx{\pgf@sys@tonumber{\tkz@cx}-\pgf@sys@tonumber{\tkz@dx}}
\FPdiv\tkz@deltaxx{\tkz@deltaxx}{28.45274}
\FPeval\tkz@deltay{\pgf@sys@tonumber{\tkz@ay}-\pgf@sys@tonumber{\tkz@by}}
\FPdiv\tkz@deltay{\tkz@deltay}{28.45274}
\FPeval\tkz@deltayy{\pgf@sys@tonumber{\tkz@cy}-\pgf@sys@tonumber{\tkz@dy}}
\FPdiv\tkz@deltayy{\tkz@deltayy}{28.45274}
\FPeval\tkz@deltaxy{(\pgf@sys@tonumber{\tkz@ax}*\pgf@sys@tonumber{\tkz@by})-(\pgf@sys@tonumber{\tkz@ay}*\pgf@sys@tonumber{\tkz@bx})}
\FPdiv\tkz@deltaxy{\tkz@deltaxy}{28.45274}
\FPdiv\tkz@deltaxy{\tkz@deltaxy}{28.45274}
\FPeval\tkz@deltaxxyy{(\pgf@sys@tonumber{\tkz@cx}*\pgf@sys@tonumber{\tkz@dy})-(\pgf@sys@tonumber{\tkz@cy}*\pgf@sys@tonumber{\tkz@dx})}
\FPdiv\tkz@deltaxxyy{\tkz@deltaxxyy}{28.45274}
\FPdiv\tkz@deltaxxyy{\tkz@deltaxxyy}{28.45274}
\FPeval\tkz@div{(\tkz@deltax*\tkz@deltayy)-(\tkz@deltay*\tkz@deltaxx)}
\FPeval\tkz@numx{(\tkz@deltaxy*\tkz@deltaxx)-(\tkz@deltax*\tkz@deltaxxyy)}
\FPeval\tkz@numy{(\tkz@deltaxy*\tkz@deltayy)-(\tkz@deltay*\tkz@deltaxxyy)}
\FPdiv\tkz@xs{\tkz@numx}{\tkz@div}
\FPdiv\tkz@ys{\tkz@numy}{\tkz@div}
\FPround\tkz@xs{\tkz@xs}{5}
\FPround\tkz@ys{\tkz@ys}{5}
\path[coordinate](\tkz@xs,\tkz@ys) coordinate (#5);
}
%<--------------------------------------------------------------------------–>
%                 intersection  de Ligne Cercle rayon connu
%<--------------------------------------------------------------------------–>
% /*
%    Calculate the intersection of a ray and a sphere
%    The line segment is defined from p1 to p2
%    The sphere is of radius r and centered at sc
%    There are potentially two points of intersection given by
%    p = p1 + mu1 (p2 - p1)
%    p = p1 + mu2 (p2 - p1)
%    Return FALSE if the ray doesn't intersect the sphere.
% */
% int RaySphere(XYZ p1,XYZ p2,XYZ sc,double r,double *mu1,double *mu2)
% {
%    double a,b,c;
%    double bb4ac;
%    XYZ dp;
% 
%    dp.x = p2.x - p1.x;
%    dp.y = p2.y - p1.y;
%    dp.z = p2.z - p1.z;
%    a = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z;
%    b = 2 * (dp.x * (p1.x - sc.x) + dp.y * (p1.y - sc.y) + dp.z * (p1.z - sc.z));
%    c = sc.x * sc.x + sc.y * sc.y + sc.z * sc.z;
%    c += p1.x * p1.x + p1.y * p1.y + p1.z * p1.z;
%    c -= 2 * (sc.x * p1.x + sc.y * p1.y + sc.z * p1.z);
%    c -= r * r;
%    bb4ac = b * b - 4 * a * c;
%    if (ABS(a) < EPS || bb4ac < 0) {
%       *mu1 = 0;
%       *mu2 = 0;
%       return(FALSE);
%    }
% 
%    *mu1 = (-b + sqrt(bb4ac)) / (2 * a);
%    *mu2 = (-b - sqrt(bb4ac)) / (2 * a);
% 
%    return(TRUE);
% }
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkz@numlc{0}
\pgfkeys{
/linecircle/.cd,
 node/.code          = \def\tkz@numlc{0},
 R/.code             = \def\tkz@numlc{1}, 
 with nodes/.code    = \def\tkz@numlc{2}  
 }
%<--------------------------------------------------------------------------–>
\def\tkzInterLC{\pgfutil@ifnextchar[{\tkz@InterLC}{%
                                     \tkz@InterLC[]}}
\def\tkz@InterLC[#1](#2,#3)(#4,#5){%
\begingroup      
\pgfkeys{/linecircle/.cd,node}
\pgfqkeys{/linecircle}{#1}
\ifcase\tkz@numlc%
 % first case 0
\tkzCalcLength(#4,#5)
\tkzInterLCR(#2,#3)(#4,\tkzLengthResult pt){%
             tkzFirstPointResult}{tkzSecondPointResult}
  \or% 1
\tkzInterLCR(#2,#3)(#4,#5){tkzFirstPointResult}{tkzSecondPointResult}%  
  \or% 2
\tkzInterLCWithNodes(#2,#3)(#4,#5){tkzFirstPointResult}{tkzSecondPointResult}% 
\fi    
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzInterLCR(#1,#2)(#3,#4)#5#6{%
\begingroup
  \tkz@radi=#4%
  \tkz@@extractxy{#3}
  \tkz@bx =\pgf@x\relax%
  \tkz@by =\pgf@y\relax%
  \tkz@Projection(#1,#2)(#3){tkz@pth}
  \tkz@@CalcLength(#3,tkz@pth){tkz@mathLen}
   \ifdim\tkz@mathLen pt<0.05pt\relax%
          \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                       {\pgfpointanchor{#2}{center}}%
          \tkz@ax=\pgf@x%
          \tkz@ay=\pgf@y%
          \tkzpointborderellipse{\pgfpoint{\tkz@ax}{\tkz@ay}}%
                                {\pgfpoint{\tkz@radi}{\tkz@radi}}
          \tkz@ax=\pgf@x\relax%
          \tkz@ay=\pgf@y\relax%
          \advance\tkz@bx by\tkz@ax\relax%
          \advance\tkz@by by\tkz@ay\relax%
          \path[coordinate] (\tkz@bx,\tkz@by) coordinate (#6);
          \tkzCSym(#3)(#6){#5} 
    \else  
       \FPdiv\pgfmathresult{\tkz@mathLen}{\pgfmath@tonumber{\tkz@radi}}
       %\pgfmathparse{\tkz@mathLen / \tkz@radi}
          \pgfmathacos@{\pgfmathresult}%
          \let\tkz@angle\pgfmathresult%
          \pgfpointdiff{\pgfpointanchor{#3}{center}}%
                       {\pgfpointanchor{tkz@pth}{center}}%
          \tkz@ax=\pgf@x%
          \tkz@ay=\pgf@y%  
          \tkzpointborderellipse{\pgfpoint{\tkz@ax}{\tkz@ay}}%
                                {\pgfpoint{\tkz@radi}{\tkz@radi}}
          \tkz@ax =\pgf@x\relax%
          \tkz@ay =\pgf@y\relax%
          \advance\tkz@bx by\tkz@ax\relax%
          \advance\tkz@by by\tkz@ay\relax%
          \tkz@@extractxy{#3}
          \tkz@ax =\pgf@x\relax%
          \tkz@ay =\pgf@y\relax%
          \tkz@@extractxy{tkz@pth}
          %\ifdim\pgf@y<\tkz@ay \edef\tkz@angle{-\tkz@angle}%
         % \fi
          \tkzmathrotatepointaround{\pgfpoint{\tkz@bx}{\tkz@by}}%
                                   {\pgfpoint{\tkz@ax}{\tkz@ay}}%
                                   {\tkz@angle}
          \path[coordinate] (\pgf@x,\pgf@y) coordinate (#5);
          \tkzmathrotatepointaround{\pgfpoint{\tkz@bx}{\tkz@by}}%
                                   {\pgfpoint{\tkz@ax}{\tkz@ay}}%
                                   {-\tkz@angle}
           \path[coordinate] (\pgf@x,\pgf@y) coordinate (#6); 
  \fi        
    \endgroup
}
%<--------------------------------------------------------------------------–>
%                 intersection  de Ligne Cercle 
% #4 center #5 point sur le cercle
%<--------------------------------------------------------------------------–>
% \def\tkzInterLC(#1,#2)(#3,#4)#5#6{%
%     \begingroup
%     \tkzCalcLength(#3,#4)\tkzGetLength{tkz@rad}
%     \tkzInterLCR(#1,#2)(#3,\tkz@rad pt){#5}{#6}
% \endgroup
% } 
%<--------------------------------------------------------------------------–>
%                 intersection  de Ligne Cercle rayon inconnu
%<--------------------------------------------------------------------------–>
\def\tkzInterLCWithNodes(#1,#2)(#3,#4,#5)#6#7{%
\begingroup
    \tkzCalcLength(#4,#5)\tkzGetLength{tkz@radius}
    \tkzInterLCR(#1,#2)(#3,\tkz@radius pt){#6}{#7}
\endgroup
}
%<--------------------------------------------------------------------------–>
%    Intersection de deux cercles  
%<--------------------------------------------------------------------------–>
\def\tkz@numcc{0}
\pgfkeys{
/circlecircle/.cd,
 node/.code          = {\global\def\tkz@numcc{0}},
 R/.code             = {\global\def\tkz@numcc{1}},
 with nodes/.code    = {\global\def\tkz@numcc{2}} 
}
%<--------------------------------------------------------------------------–>
\def\tkzInterCC{\pgfutil@ifnextchar[{\tkz@InterCC}{%
                                     \tkz@InterCC[]}}
\def\tkz@InterCC[#1](#2,#3)(#4,#5){%
\begingroup      
\pgfkeys{/circlecircle/.cd,node}
\pgfqkeys{/circlecircle}{#1}
\ifcase\tkz@numcc%
 % first case 0 
\tkz@save@length 
  \tkzCalcLength(#2,#3)\tkzGetLength{tkz@rayA}
  \tkzCalcLength(#4,#5)\tkzGetLength{tkz@rayB}
\tkz@restore@length     
  \tkzInterCCR(#2,\tkz@rayA pt)(#4,\tkz@rayB pt){tkzFirstPointResult}{%
                                                 tkzSecondPointResult}   
  \or% 1
   \tkzInterCCR(#2,#3)(#4,#5){tkzFirstPointResult}{tkzSecondPointResult}%
   \or%2
\tkzInterCCWithNodes(#2,#3)(#4,#5){tkzFirstPointResult}{tkzSecondPointResult}    
     \fi   
\endgroup
} 
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>

% méthode
% /* circle_circle_intersection() *
%  * Determine the points where 2 circles in a common plane intersect.
%  *
%  * int circle_circle_intersection(
%  *                                // center and radius of 1st circle
%  *                                double x0, double y0, double r0,
%  *                                // center and radius of 2nd circle
%  *                                double x1, double y1, double r1,
%  *                                // 1st intersection point      
%  *                                // 2nd intersection point
%  *
%  * This is a public domain work. 3/26/2005 Tim Voght
%  *
% int circle_circle_intersection(double x0, double y0, double r0,
%                                double x1, double y1, double r1,
%                                double *xi, double *yi,
%                                double *xi_prime, double *yi_prime)
% {
%   double a, dx, dy, d, h, rx, ry;
%   double x2, y2;
% 
%   /* dx and dy are the vertical and horizontal distances between
%    * the circle centers.
%    */
%   dx = x1 - x0;
%   dy = y1 - y0;
% 
%   /* Determine the straight-line distance between the centers. */
%   //d = sqrt((dy*dy) + (dx*dx));
%   d = hypot(dx,dy); // Suggested by Keith Briggs
% 
%   /* Check for solvability. */
%   if (d > (r0 + r1))
%   {
%     /* no solution. circles do not intersect. */
%     return 0;
%   }
%   if (d < fabs(r0 - r1))
%   {
%     /* no solution. one circle is contained in the other */
%     return 0;
%   }
% 
%   /* 'point 2' is the point where the line through the circle
%    * intersection points crosses the line between the circle
%    * centers.  
%    */
% 
%   /* Determine the distance from point 0 to point 2. */
%   a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
% 
%   /* Determine the coordinates of point 2. */
%   x2 = x0 + (dx * a/d);
%   y2 = y0 + (dy * a/d);
% 
%   /* Determine the distance from point 2 to either of the
%    * intersection points.
%    */
%   h = sqrt((r0*r0) - (a*a));
% 
%   /* Now determine the offsets of the intersection points from
%    * point 2.
%    */
%   rx = -dy * (h/d);
%   ry = dx * (h/d);
% 
%   /* Determine the absolute intersection points. */
%   *xi = x2 + rx;
%   *xi_prime = x2 - rx;
%   *yi = y2 + ry;
%   *yi_prime = y2 - ry;
% 
%   return 1;
% } 

\def\tkzInterCCR(#1,#2)(#3,#4)#5#6{%
\begingroup
\tkz@save@length  
\tkzCalcLength(#1,#3)\tkzGetLength{tkz@dd}
\tkz@restore@length 
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}} 
\tkz@ax\pgf@x %
\tkz@ay\pgf@y %
\pgfextractx{\pgf@x}{\pgfpointanchor{#3}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#3}{center}} 
\tkz@bx\pgf@x %
\tkz@by\pgf@y %
\tkz@cx#2 %
\tkz@cy#4 %
\FPeval\tkz@aa{((\pgf@sys@tonumber{\tkz@cx}+\pgf@sys@tonumber{\tkz@cy})/(2*\tkz@dd))*(\pgf@sys@tonumber{\tkz@cx}-\pgf@sys@tonumber{\tkz@cy})+\tkz@dd/2}

\FPeval\tkz@xx{\pgf@sys@tonumber{\tkz@ax}+\tkz@aa/\tkz@dd*(\pgf@sys@tonumber{\tkz@bx} - \pgf@sys@tonumber{\tkz@ax})}
\FPeval\tkz@yy{\pgf@sys@tonumber{\tkz@ay}+\tkz@aa/\tkz@dd*(\pgf@sys@tonumber{\tkz@by} - \pgf@sys@tonumber{\tkz@ay})}   
\path[coordinate](\tkz@xx pt,\tkz@yy pt) coordinate (tkzRadialCenter);
\FPeval\tkz@hh{(\pgf@sys@tonumber{\tkz@cx}+\tkz@aa)*(\pgf@sys@tonumber{\tkz@cx}-\tkz@aa)}
\FPpow\tkz@hh{\tkz@hh}{0.5}
\FPeval\tkz@rx{\tkz@hh / \tkz@dd * (\pgf@sys@tonumber{\tkz@ay} - \pgf@sys@tonumber{\tkz@by}) } 
\FPeval\tkz@ry{\tkz@hh / \tkz@dd * (\pgf@sys@tonumber{\tkz@bx} - \pgf@sys@tonumber{\tkz@ax}) }
\FPadd\tkz@xs{\tkz@xx}{\tkz@rx }
\FPadd\tkz@ys{\tkz@yy}{\tkz@ry }
\path[coordinate](\tkz@xs pt,\tkz@ys pt) coordinate (#5);
\FPadd\tkz@xss{\tkz@xx}{-\tkz@rx }
\FPadd\tkz@yss{\tkz@yy}{-\tkz@ry }
\path[coordinate](\tkz@xss pt,\tkz@yss pt) coordinate (#6);  
\endgroup
}
%<--------------------------------------------------------------------------–>
% #2 node #3 node #4 node #5 node
% \def\tkzInterCC(#1,#2)(#3,#4)#5#6{%
% \begingroup
%   \tkzCalcLength(#1,#2)\tkzGetLength{tkz@rayA}
%   \tkzCalcLength(#3,#4)\tkzGetLength{tkz@rayB}
%   \tkzInterCCR(#1,\tkz@rayA pt)(#3,\tkz@rayB pt){#5}{#6}
% \endgroup
% }  
%<--------------------------------------------------------------------------–>
%    Intersection de deux cercles   Avec deux points
%<--------------------------------------------------------------------------–>
% la première variante devrait être #2 #3  avec #4 #5
\def\tkzInterCCWithNodes(#1,#2,#3)(#4,#5,#6)#7#8{%
\begingroup
  \tkzCalcLength(#2,#3)\tkzGetLength{tkz@rayA}
  \tkzCalcLength(#5,#6)\tkzGetLength{tkz@rayB}
  \tkzInterCCR(#1,\tkz@rayA pt)(#4,\tkz@rayB pt){#7}{#8}
\endgroup
}

%<--------------------------------------------------------------------------–>
%    tangente à cercle passant par un point donné
%<--------------------------------------------------------------------------–>
\def\tkzTgtFromPR(#1,#2)(#3){%
    \begingroup
    \tkzDefMidPoint(#1,#3) 
    \tkzCalcLength(tkzPointResult,#1)
    \tkzInterCCR(#1,#2)(tkzPointResult,\tkzLengthResult pt){%
    tkzFirstPointResult}{%
    tkzSecondPointResult}%
    \endgroup
}

\def\tkzTgtFromP(#1,#2)(#3){%
    \begingroup
    \tkzDefMidPoint(#1,#3) 
    \tkzCalcLength(#1,#2)\tkzGetLength{tkz@radone}%
    \tkzCalcLength(tkzPointResult,#1)\tkzGetLength{tkz@radtwo}%
    \tkzInterCCR(#1,\tkz@radone pt)(tkzPointResult,\tkz@radtwo pt){%
    tkzFirstPointResult}{%
    tkzSecondPointResult}%
    \endgroup
}     
\def\tkzTgtAt(#1)(#2){%
\begingroup
     \tkz@VecKOrthNorm[-1](#2,#1){tkzPointResult}
 \endgroup
} %<--------------------------------------------------------------------------–> %<--------------------------------------------------------------------------–>
\def\tkz@numtang{0}
\pgfkeys{
/tang/.cd,
at/.code          = {\global\def\tkz@numtang{0}\global\def\tkz@ptat{#1}},
from/.code        = {\global\def\tkz@numtang{1}\global\def\tkz@ptfrom{#1}},
from with R/.code = {\global\def\tkz@numtang{2}\global\def\tkz@ptfrom{#1}}}
%<--------------------------------------------------------------------------–>
\def\tkzTangent{\pgfutil@ifnextchar[{\tkz@Tangent}{\tkz@Tangent[]}}

\def\tkz@Tangent[#1](#2){%
\begingroup
\pgfkeys{tang/.cd}
\pgfqkeys{/tang}{#1}
\ifcase\tkz@numtang
    \tkzTgtAt(#2)(\tkz@ptat)
\or
   \tkzTgtFromP(#2)(\tkz@ptfrom)
 \or
   \tkzTgtFromPR(#2)(\tkz@ptfrom)
\fi 
\endgroup
}   

\endinput