I try to make a function that calculate intersection points between to circles: one circle against a list of circles.
For each case there are 0,1 or 2 intersection points.
I want the function returns nil, nil for 0 points, z0, nil for 1 and z1, z2 for 2 points. I thought collecting gradually the pairs of results in a table through a loop, and unpack it at the end, but a table doesn't take a nil value.
I tried this for the moment. How can I achieve what I want ?
function InterSection_Cercles (Ca , ... )
local C = table.pack( ... )
local d, CosTheta, Theta, i
local t = {}
for i = 1, C.n do
d = complex.abs ( Ca.Ct - C[i].Ct )
CosTheta = round (((Ca.Ry * Ca.Ry + d * d - C[i].Ry * C[i].Ry) /( 2 * Ca.Ry * d )) , 10 )
Theta = round ( math.acos( CosTheta ) , Prec)
if not Theta then -- 0 solution
-- table.insert( t , nil ) useless
-- table.insert( t , nil )
elseif Theta == 0 then -- 1 solution
table.insert( t , Ca.Ct + complex.polar (Ca.Ry , Theta + complex.arg (C[i].Ct -Ca.Ct)))
-- table.insert( t , nil ) useless
else -- 2 solitions
table.insert( t , Ca.Ct + complex.polar (Ca.Ry , Theta + complex.arg (C[i].Ct -Ca.Ct)))
table.insert( t , Ca.Ct + complex.polar (Ca.Ry , -Theta + complex.arg (C[i].Ct -Ca.Ct)))
end -- if
end -- for
return table.unpack ( t )
end -- function