TGC Codebase Backup



circle intersection by Phaelax

28th Jan 2004 22:03
Summary

Finds single initial point of intersection between two circles



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    
REM Point of intersection between two circles
REM written by: Phaelax

x1# = 300
y1# = 200
r1# = 50
r2# = 30

do
   cls
   x2#=mousex()
   y2#=mousey()


   ink rgb(255,255,255),0
   circle x1#,y1#,r1#
   circle x2#,y2#,r2#


   rem only calculate point of intersection if circles are intersecting
   if (x1#-x2#)^2 + (y1#-y2#)^2 <= (r1#+r2#)^2
      dx#=x2#-x1#
      dy#=y2#-y1#
      angle#=atanfull(dx#,dy#)
      x# = newxvalue(x1#,angle#,r1#)
      y# = newzvalue(y1#,angle#,r1#)

      rem show point of intersection
      ink rgb(255,0,0),0
      circle x#, y#,2
   endif

loop