REM *********************************************** REM Title: Intersection of 2 ellipses REM Author: Phaelax REM Downloaded from: http://dbcc.zimnox.com/ REM *********************************************** sync on randomize timer() rem ellipse 1 x1# = 320 y1# = 240 a1# = 60 b1# = 25 rem ellipse 2 x2# = mousex() y2# = mousey() a2# = rnd(40)+20 b2# = rnd(40)+20 REPEAT cls rem center of ellipse 2 x2# = mousex() y2# = mousey() ink rgb(255,255,255),0 if CXEllipseR2(x1#,y1#,a1#,b1#,x2#,y2#,a2#,b2#) = 1 then ink rgb(255,0,0),0 rem draw ellipses ellipse x1#,y1#,a1#,b1# ellipse x2#,y2#,a2#,b2# sync UNTIL spacekey() END function CXEllipseR2(x1#,y1#,radiusX1#,radiusY1#, x2#,y2#,radiusX2#,radiusY2#) rem convert the space of the two ellipses rem the unit circle rX1# = x1#/radiusX1# rY1# = y1#/radiusY1# rem 2nd ellipse rX2# = x2#/radiusX1# rY2# = y2#/radiusY1# rRadiusX2# = radiusX2#/radiusX1# rRadiusY2# = radiusY2#/radiusY1# rem find the point on the ellipse nearest to the unit circle a# = atanfull(rX1#-rX2#, rY1#-rY2#) x# = rX2#+sin(a#)*rRadiusX2# y# = rY2#+cos(a#)*rRadiusY2# rem check the distance if (rX1#-x#)^2 + (rY1#-y#)^2 <= 1.0 then exitfunction 1 endfunction 0