>q?ÿÿðÿðððÿðÿðÿÿðÿÿðÿÿðÿÿÿÿðððÿÿÿÿÿðÿÿððÿÿÿÿðÿÿÿðÿðÿÿðÿÿÿðð033333333333030333303030300003000300000000000000 0000000000000000000000000000000000000000000000000000000300030030303030330303333303333333ÿÿðÿðÿðððððÿðððððÿÿÿÿððÿððÿððÿðððÿððÿÿðððððÿðððÿÿÿðÿÿðÿððÿÿðÿððÿÿðððð-- title: point & circ collision -- author: txgruppi -- desc: a simple tool to visualize how we can detect collisions between a point and a circle -- site: https://github.com/txgruppi -- license: MIT License -- version: 0.3 -- script: lua -- changelog -- -- 2023-05-16: removed sqrt in favor of r^2 as suggested by @congusbongus -- 2023-01-11: Moved collision check code to its own function local sqrt = math.sqrt local pow = math.pow local r = 50 local x = 5 local y = 10 local cx = 240/2 local cy = 136/2 function clamp(min,curr,max) if currmax then return max end return curr end function check_point_circ_coll(px, py, cx, cy, cr) return pow(cy-py,2)+pow(cx-px,2) <= r^2 end function TIC() if btn(0) then y=y-1 end if btn(1) then y=y+1 end if btn(2) then x=x-1 end if btn(3) then x=x+1 end if btn(4) then r=r+1 end if btn(5) then r=r-1 end y=clamp(0,y,135) x=clamp(0,x,239) r=clamp(1,r,50) local coll=check_point_circ_coll(x, y, cx, cy, r) local c=14 if coll then c=3 end cls(0) circb(240/2,136/2,r,c) pix(x,y,13) print("x="..x.." y="..y.." cx="..cx.." cy="..cy.." r="..r,0,0,15,true,1,true) print("pow(cy-y,2)+pow(cx-x,2) <= r^2 == "..tostring(coll),0,130,15,true,1,true) end