luageometryradius

How to get circumcircle midpoint and radius in Lua?


I've tried to make a function in Lua to get the circumcircle, circumcenter and radius, but something goes wrong:

local function getCircumcircle (x1, y1, x2, y2, x3, y3)
    local d = 2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))
    local t1, t2, t3 = x1*x1+y1*y1, x2*x2+y2*y2, x3*x3+y3*y3
    local x = (t1*(y2-y3)+t2*(y3-y1)+t3*(y1-y2))/d
    local y = (t1*(x3-x2)+t2*(x1-x3)+t3*(x2-x1))/d
    local radius = math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y))
end

Solution

  • Thanks, Ivo, my bad.

    local function getCircumcircle (x1, y1, x2, y2, x3, y3)
        local d = 2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))
        local t1, t2, t3 = x1*x1+y1*y1, x2*x2+y2*y2, x3*x3+y3*y3
        local x = (t1*(y2-y3)+t2*(y3-y1)+t3*(y1-y2))/d
        local y = (t1*(x3-x2)+t2*(x1-x3)+t3*(x2-x1))/d
        local radius = math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y))
        return x,y,radius
    end