lib/ball.rb
# returns false if no intersection, else the intersection point

returns false if no intersection, else the intersection point
returns false if no intersection else the intersection point
def intersection(x, y, rx, ry, bx, by, sx, sy)
      return false if (rx * sy) - (sx * ry) == 0
      t = ((y - by) * sx - sy * (x - bx)) / ((rx * sy) - (sx * ry))
      u = ((y - by) * rx - ry * (x - bx)) / ((rx * sy) - (sx * ry))
      return [bx+((u-0.7)*sx), by+((u-0.7)*sy)] if u.between?(0,1) && t.between?(0,1)
      return false
    end
def intersection ( x , y , rx , ry , bx , by , sx , sy ) return false if ( rx * sy ) - ( sx * ry ) == 0 t = ( ( y - by ) * sx - sy * ( x - bx ) ) / ( ( rx * sy ) - ( sx * ry ) ) u = ( ( y - by ) * rx - ry * ( x - bx ) ) / ( ( rx * sy ) - ( sx * ry ) ) return [ bx + ( ( u - 0.7 ) * sx ) , by + ( ( u - 0.7 ) * sy ) ] if u . between? ( 0 , 1 ) && t . between? ( 0 , 1 ) return false end
returns false if no intersection, else the intersection point
returns false if no intersection else the intersection point
#Determinant Check (Parallel or collinear)
 #Paramters:
 # t = ((p1.y-p4.y) * bx) - (by * (p1.x-p4.x)) / ((rx*by) - (bx*ry))
 # u = ((p1.y-p4.y) * rx) - (ry * (p1.x-p4.x)) / ((rx*by) - (bx*ry))
 #Collison check

x
y
rx
ry
bx
by
sx
sy