%% syntaxe : cerc1 cerc2 intercercle --> A B les points d'intersection
%% des 2 cercles, tries par 'ordonnepoints'
/intercercle {
12 dict begin
/r2 exch def
/y2 exch def
/x2 exch def
/r1 exch def
/y1 exch def
/x1 exch def
%% on translate pour se ramener a (x1, y1) = (0, 0)
x2 y2 x1 y1 subv
/y2 exch def
/x2 exch def
%% on prepare l'equation du 2nd degre
%% 2 2 2
%% {y = RootOf((4 x2 + 4 y2 ) _Z
%%
%% 3 2 2 2 4
%% + (-4 y2 - 4 r1~ y2 + 4 y2 r2~ - 4 x2 y2) _Z + x2
%%
%% 4 2 2 2 2 2 2 2 2
%% + r2~ - 2 y2 r2~ + 2 x2 y2 - 2 x2 r2~ - 2 r1~ x2
%%
%% 4 4 2 2 2 2
%% + r1~ + y2 + 2 r1~ y2 - 2 r1~ r2~ ), x = 1/2 (-2 y2
%%
%% 2 2 2
%% RootOf((4 x2 + 4 y2 ) _Z
%%
%% 3 2 2 2 4
%% + (-4 y2 - 4 r1~ y2 + 4 y2 r2~ - 4 x2 y2) _Z + x2
%%
%% 4 2 2 2 2 2 2 2 2
%% + r2~ - 2 y2 r2~ + 2 x2 y2 - 2 x2 r2~ - 2 r1~ x2
%%
%% 4 4 2 2 2 2 2 2 2
%% + r1~ + y2 + 2 r1~ y2 - 2 r1~ r2~ ) + r1~ + x2 + y2
%%
%% 2
%% - r2~ )/x2}
%% coeff pour le degre 2
/a
%% 2 2 2
%% {y = RootOf((4 x2 + 4 y2 ) _Z
4 x2 dup mul mul
4 y2 dup mul mul add
def
%% coeff pour le degre 1
%%
/b
%% 3 2 2 2
%% + (-4 y2 - 4 r1~ y2 + 4 y2 r2~ - 4 x2 y2) _Z
-4 y2 3 exp mul
4 r1 dup mul mul y2 mul sub
4 r2 dup mul mul y2 mul add
4 x2 dup mul mul y2 mul sub
def
%% coeff pour le degre 0
%%
/c {
%% 4
%% + x2
x2 4 exp
%%
%% 4 2 2 2 2 2 2 2 2
%% + r2~ - 2 y2 r2~ + 2 x2 y2 - 2 x2 r2~ - 2 r1~ x2
r2 4 exp add
2 y2 dup mul mul r2 dup mul mul sub
2 x2 dup mul mul y2 dup mul mul add
2 x2 dup mul mul r2 dup mul mul sub
2 x2 dup mul mul r1 dup mul mul sub
%%
%% 4 4 2 2 2 2
%% + r1~ + y2 + 2 r1~ y2 - 2 r1~ r2~ )
r1 4 exp add
y2 4 exp add
2 r1 dup mul mul y2 dup mul mul add
2 r1 dup mul mul r2 dup mul mul sub
} def
a b c solve2nddegre
/Y1 exch def
/Y0 exch def
/X0
%% x = 1/2 (-2 y2 Y
-2 y2 mul Y0 mul
%%
%% 2 2 2
%% + r1~ + x2 + y2
r1 dup mul add
x2 dup mul add
y2 dup mul add
%%
%% 2
%% - r2~ )/x2}
r2 dup mul sub
2 x2 mul div
def
/X1
%% x = 1/2 (-2 y2 Y
-2 y2 mul Y1 mul
%%
%% 2 2 2
%% + r1~ + x2 + y2
r1 dup mul add
x2 dup mul add
y2 dup mul add
%%
%% 2
%% - r2~ )/x2}
r2 dup mul sub
2 x2 mul div
def
%% on depose le resultat, en n'oubliant pas de retranslater en sens
%% inverse
X0 Y0 x1 y1 addv
X1 Y1 x1 y1 addv
ordonnepoints
end
} def
|