Hmmm, tricky problem, but I think this should do it, it even allows for concave quadrilaterals (shaped like arrowheads)
sync on : sync rate 40
randomize timer()
hide mouse
` set quadrilateral (set clockwise)
x1 = rnd(100) + 100 : y1 = rnd(100) + 100
x2 = rnd(100) + 439 : y2 = rnd(100) + 100
x3 = rnd(100) + 439 : y3 = rnd(100) + 279
x4 = rnd(100) + 100 : y4 = rnd(100) + 279
` turn on this line to test a concave quadrilateral
`x4 = 400 : y4 = 210
repeat
cls
mx = mousex() : my = mousey()
` draw quad
line x1,y1,x2,y2 : line x2,y2,x3,y3
line x3,y3,x4,y4 : line x4,y4,x1,y1
` draw cross at mouse position
line mx-10,my,mx+10,my
line mx,my-10,mx,my+10
` check if mouse inside quad
q = CheckQuadPoint(mx,my, x1,y1,x2,y2,x3,y3,x4,y4)
if q = 1
center text mx,my + 12,"Inside"
else
center text mx,my + 12,"Outside"
endif
sync
until scancode() <> 0
end
` ------------------------------------------------------------------------
function CheckQuadPoint(px,py, x1,y1,x2,y2,x3,y3,x4,y4)
a as float : c as float
xd = abs(x3-x1) : yd = abs(y3-y1) : d1 = (xd*xd) + (yd*yd)
xd = abs(x4-x2) : yd = abs(y4-y2) : d2 = (xd*xd) + (yd*yd)
if d1 < d2
ax = x3 : ay = y3
bx = x1 : by = y1
else
ax = x4 : ay = y4
bx = x2 : by = y2
endif
a = TriArea(x1,y1,x2,y2,ax,ay)
c = TriArea(px,py,x2,y2,ax,ay) + TriArea(x1,y1,px,py,ax,ay) + TriArea(x1,y1,x2,y2,px,py)
if a = c then exitfunction 1
a = TriArea(bx,by,x3,y3,x4,y4)
c = TriArea(px,py,x3,y3,x4,y4) + TriArea(bx,by,px,py,x4,y4) + TriArea(bx,by,x3,y3,px,py)
if a = c then exitfunction 1
endfunction 0
function TriArea(ax,ay,bx,by,cx,cy)
area as float
area = abs((bx*ay-ax*by)+(cx*by-bx*cy)+(ax*cy-cx*ay))/2
endfunction area
...the only problem you might have is when areas of the quadrilateral become to thin to check if the point is in or out, but larger areas are no problem.
Hope this helps
edit: Oh yes, I almost forgot, those two functions are 22 lines and no sqrts
Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.