I am trying to implement a mathematical procedure to ensure that a circle c1 is completely inside another circle c2.
It should work the following way:
Given c1(x, y, r) and c2(x, y, r) and c2.r>c1.r
- return true if c1 is inside c2
- return a vector V(x,y) being the minimum correction to apply to c1 so it is inside c2.
How does it look to you? should be easy for a mathematician or a physicist but it's quite hard for me.
I already tried an implementation in lua, but there's definitely something wrong on it.
local function newVector(P1, P2)
local w, h=(P2.x-P1.x), (P2.y-P1.y)
local M=math.sqrt(w^2 + h^2)
local alpha=math.atan(h/w)
return {m=M, alpha=alpha}
end
local function isWithin(C1, C2)
local V12=newVector(C1, C2)
local R12=C2.r-C1.r
local deltaR=R12-V12.m
if deltaR>=0 then
return true
else
local correctionM=(V12.m+deltaR) --module value to correct
local a=V12.alpha
print("correction angle: "..math.deg(a))
local correctionX=correctionM*math.cos(a)
local correctionY=correctionM*math.sin(a)
return {x=correctionX, y=correctionY}
end
end
Thanks!