| 1 |
-- search_circle.lua |
| 2 |
local r = ... |
| 3 |
|
| 4 |
function newcircle(T, C) |
| 5 |
-- homothétie du triangle à partir de l’incentre |
| 6 |
local k = 1 + C.radius / T.inradius |
| 7 |
local NT = T.incenter:homothety(k, T) |
| 8 |
|
| 9 |
-- les deux côtés qui encadrent le cercle cherché |
| 10 |
local Lba = line(NT.pb, NT.pa) |
| 11 |
local Lbc = line(NT.pb, NT.pc) |
| 12 |
|
| 13 |
-- cercles tangent à Lba et Lbc et passant par C.center |
| 14 |
local pc, pa = Lba:LLP(Lbc, C.center) |
| 15 |
|
| 16 |
-- petite fonction utilitaire : construit le candidat n |
| 17 |
local function candidate(idx) |
| 18 |
local w = pc:get(idx) |
| 19 |
if not w then return nil end |
| 20 |
local t = T.bc:projection(w) |
| 21 |
local r_new = w:length(t) -- rayon du nouveau cercle |
| 22 |
local d = w:length(C.center) -- distance entre centres |
| 23 |
return w, t, r_new, d |
| 24 |
end |
| 25 |
|
| 26 |
local w1, t1, r1, d1 = candidate(1) |
| 27 |
local w2, t2, r2, d2 = candidate(2) |
| 28 |
|
| 29 |
local EPS = tkz.epsilon or 1e-6 |
| 30 |
|
| 31 |
-- test de tangence externe avec C |
| 32 |
local function good_ext(d, r_new) |
| 33 |
return math.abs(d - (r_new + C.radius)) < 10 * EPS |
| 34 |
end |
| 35 |
|
| 36 |
-- choix du bon candidat |
| 37 |
if w1 and good_ext(d1, r1) and not (w2 and good_ext(d2, r2)) then |
| 38 |
return w1, t1 |
| 39 |
elseif w2 and good_ext(d2, r2) and not (w1 and good_ext(d1, r1)) then |
| 40 |
return w2, t2 |
| 41 |
elseif w1 and w2 then |
| 42 |
-- si les deux ou aucun ne passent le test, on prend par défaut |
| 43 |
-- le cercle de plus petit rayon (habituellement le cercle intérieur) |
| 44 |
if r1 <= r2 then |
| 45 |
return w1, t1 |
| 46 |
else |
| 47 |
return w2, t2 |
| 48 |
end |
| 49 |
else |
| 50 |
-- pas de solution exploitable |
| 51 |
return nil, nil |
| 52 |
end |
| 53 |
end |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
z.A = point:new(0, 0) |
| 58 |
z.B = point:new(8, 0) |
| 59 |
z.C = point:new(2, 6) |
| 60 |
T.ABC = triangle:new(z.A, z.B, z.C) |
| 61 |
L.bA = T.ABC:bisector() |
| 62 |
z.c1 = L.bA:report(r) |
| 63 |
z.t1 = T.ABC.ab:projection(z.c1) |
| 64 |
C.last = circle:new(z.c1, z.t1) |
| 65 |
|
| 66 |
local vertices = { "A", "B", "C" } |
| 67 |
for i = 2, 6 do |
| 68 |
T.used = triangle:new( |
| 69 |
z[vertices[math.fmod(i - 2, 3) + 1]], |
| 70 |
z[vertices[math.fmod(i - 1, 3) + 1]], |
| 71 |
z[vertices[math.fmod(i, 3) + 1]] |
| 72 |
) |
| 73 |
z["c" .. i], z["t" .. i] = newcircle(T.used, C.last) |
| 74 |
C.last = circle:new(z["c" .. i], z["t" .. i]) |
| 75 |
end |