Point in ellipse

Someone has probably done this before(sorry if they have) but I wrote some code to find if a point is in an ellipse. (It can be made better and faster)


function setup()
    parameter.number("width",50,200)
    parameter.integer("height",50,200)
    pos=vec2(WIDTH/2,HEIGHT/2)
    col=color(255)
end

function draw()
    background(0)
    fill(col)
    ellipseMode(RADIUS)
    ellipse(pos.x,pos.y,width,height)
end

function touched(t)
    local tpos=vec2(t.x,t.y)-pos
    local angle=angleToPoint(vec2(0,0),tpos)
    local edge=vec2(math.sin(math.rad(angle))*width,math.cos(math.rad(angle))*height)
    local rad=vec2(0,0):dist(edge)
    local d=vec2(0,0):dist(tpos)
    if d<=rad then col=color(255,0,0)else col=color(255)end
end

function angleToPoint(ptA,ptB)
    local angle=math.deg(math.atan2(ptA.y-ptB.y,ptA.x-ptB.x))
    angle = angle + 90
    return angle
end

@Coder Here one that I wrote long time ago if you want to see another version.

function setup()
    parameter.integer("a",1,400,200)    -- size of a axis
    parameter.integer("b",1,400,100)    -- size of b axis
    xc=250    -- center of ellipse x axis
    yc=400    -- center of ellipse y axis
end

function draw()
    background(40, 40, 50)    
    fill(255)
    ellipse(xc,yc,a*2,b*2)    -- draw ellipse   
    x=CurrentTouch.x    -- touched x value
    y=CurrentTouch.y    -- touched y value        
    fill(255,0,0)
    ellipse(x,y,5)  -- draw point  
    -- check if point is inside of ellipse
    if (x-xc)^2/a^2+(y-yc)^2/b^2 <= 1 then 
        text("point in ellipse",xc,yc)        
    end    
end