Search code examples
mathluatrigonometry

Find Intersection Point of Two Parabolas Given Their Focuses and Common Directrix [Lua]


I have two parabolas defined by their respective focuses ((fx1, fy1) and (fx2, fy2)), and a common directrix dirY.

I need to find the intersection point of these two parabolas with given height of intersection (y).

I have very long solution, but is here a way to make it shorter, without a, b, c?

local function twoParabolasCrossByHeight (fx1, fy1, fx2, fy2, dirY, y)
    local f1 = math.abs(dirY-fy1)/2
    local f2 = math.abs(dirY-fy2)/2

    if fy1 == fy2 then
        return (fx1+fx2)/2, y
    end
    local a1 = -1/(4*f1)
    local a2 = -1/(4*f2)
    local b1 = -2*fx1*a1
    local b2 = -2*fx2*a2
    local c1 = fx1*fx1*a1 + fy1 + f1
    local c2 = fx2*fx2*a2 + fy2 + f2
    local a = a1-a2
    local b = b1-b2
    local c = c1-c2

    local d = b*b-4*a*c
    if d < 0 then return end
    local x1 = (-b-math.sqrt (d))/(2*a)
    local y1 = a1*x1*x1 + b1*x1 + c1
    return x1, y1
end

Two examples:

 -- must be 400 50:
print (twoParabolasCrossByHeight (250, 250, 550, 250, 300, 50))

 -- must be aprox. 400  50:
print (twoParabolasCrossByHeight (250, 250, 550, 251, 300, 50))

Two Parabolas and Line Crossing


Solution

  • It was relative easy: two parabolas with given focus crossing as line.

    The result line is perpendicular bisector between two points:

    function focusFocusLineYCrossing (p1x, p1y, p2x, p2y, y)
        local cx = (p1x+p2x)/2
        local cy = (p1y+p2y)/2
        local m = (p2y-p1y)/(p2x-p1x) -- slope
        local x = cx - m*(y-p1y) -- perpendicular to slope
        return x
    end
    

    crossing of two parabolas