Rectangle-ellipse collision check HELP

Ok.  So for the last three days I have been working on a collision system for my battle system.  I have tried several algorithms out there and have yet to find one that works with ellipses.

I can get the x-axis collision right but not the y-axis collision or the other way around.

If someone can help me find the math needed.  I will be very, very gratefull to you.

Help please!
What I could think is using integral atm, but I doubt you would like that. May I see how you do determine the x-coord collision? I might be able to adapt to your style and provide the y-coord collision in a comfortable equation.
This is the one I currently am using, but I have others. 

cx = circle origin x

cy = circle origin y

rx = radius x ways

yx = radius y ways

rect = rectangle that gets in range

Code:
module Intersect    def self.intersects(cx,cy,rx, rect, ry)      #Find the closest point to the circle within the rectangl    closestX = [rect.width + rect.x, [cx, rect.x].max].min    closestY = [rect.height + rect.y, [cy,rect.y].max].min    #Calculate the distance between the circle's center and this closest point    distanceX = cx - closestX     distanceY = cy - closestY    #If the distance is less than the circle's radius, an intersection occurs    distanceSquared = ((distanceX * distanceX) + (distanceY * distanceY))    answer =  distanceSquared < (rx * rx)    if answer      return distanceSquared < (ry * ry)    end  endendend
I gotta go now, I got the conditional branch on the return value mixed up between && and ||.

I'll fix that up later though if someone would like to pick this up, feel free to do so.

Code:
#RPG Maker VX Acemodule Intersect  def self.rect_ellipse(cx,cy,rx, ry, rect)    "origin = (cx, cy)"    "rx, ry = radius of perspective-axis"        "ellipse equation => (x-cx/rx)^2 + (y-cy/ry)^2 = 1"        "1 - (cx/rx)^2 = (cy/ry)^2"        "(1 - (cx/rx)^2)^.5 = cy/ry"        "cy = ry * (1 - (cx/rx)^2)^.5"        cx_f = cx.to_f        return ((rect.x + rect.width).between?(cx - rx, cx + rx) ||           ((rect.y + rect.height).between?(get_uy(rect.x + rect.width, cx_f, cy,rx, ry),                                             get_ly(rect.x + rect.width, cx_f, cy, rx, ry)) ||            (rect.y - rect.height).between?(get_uy(rect.x + rect.width, cx_f, cy,rx, ry),                                             get_ly(rect.x + rect.width, cx_f, cy, rx, ry)))) ||           ((rect.x - rect.width).between?(cx - rx, cx + rx) ||                                            ((rect.y + rect.height).between?(get_uy(rect.x - rect.width, cx_f, cy,rx, ry),                                             get_ly(rect.x - rect.width, cx_f, cy, rx, ry)) ||            (rect.y - rect.height).between?(get_uy(rect.x - rect.width, cx_f, cy,rx, ry),                                             get_ly(rect.x - rect.width, cx_f, cy, rx, ry))));          end  "f(x) upper divission"  def self.get_uy(x, cx_f,cy,rx, ry)    return (ry * Math.sqrt((1 - (x - cx_f) / rx * (x - cx_f) / rx).abs.to_i).to_i) + cy  end    "f(x) lower divission"  def self.get_ly(x, cx_f, cy, rx, ry)    return (-ry * Math.sqrt((1 - (x - cx_f)/rx * (x - cx_f)/rx).abs.to_i).to_i) + cy  end  end
Update:

#RPG Maker VX Acemodule Intersect def self.rect_ellipse(cx,cy,rx, ry, rect) "origin = (cx, cy)" "rx, ry = radius of perspective-axis" "ellipse equation => (x-cx/rx)^2 + (y-cy/ry)^2 = 1" "1 - ((x -cx)/rx)^2 = (cy/ry)^2" "(1 - ((x- cx)/rx)^2)^.5 = cy/ry" "y = ry * (1 - (cx/rx)^2)^.5 + cy" cx_f = cx.to_f if rect.x + rect.width > cx + rx || rect.x - rect.width < cx - rx || rect.y + rect.height > cy + ry || rect.y - rect.height < cy - ry return false else return ((rect.y + rect.height).between?(get_ly(rect.x + rect.width, cx_f, cy,rx, ry), get_uy(rect.x + rect.width, cx_f, cy, rx, ry)) || (rect.y - rect.height).between?(get_ly(rect.x + rect.width, cx_f, cy,rx, ry), get_uy(rect.x + rect.width, cx_f, cy, rx, ry))) || ((rect.y + rect.height).between?(get_ly(rect.x - rect.width, cx_f, cy,rx, ry), get_uy(rect.x - rect.width, cx_f, cy, rx, ry)) || (rect.y - rect.height).between?(get_ly(rect.x - rect.width, cx_f, cy,rx, ry), get_uy(rect.x - rect.width, cx_f, cy, rx, ry))); end end "f(x) upper divission" def self.get_uy(x, cx_f,cy,rx, ry) return ry * (1 - Math.sqrt(((x - cx_f) / rx * (x - cx_f) / rx).abs.to_i).to_i) + cy end "f(x) lower divission" def self.get_ly(x, cx_f, cy, rx, ry) return -ry * (1 - Math.sqrt(((x - cx_f) / rx * (x - cx_f) / rx).abs.to_i).to_i) + cy end endLet me know if this works or not.

Edit:

You might want to remove the integer conversion.

I just found out that between?(a, 😎 and sqrt() can take float value.
Ok, I figured it out thanks to you.

Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/rectangle-ellipse-collision-check-help.23132/