Here is my circle intersect line segment detector, thanks to james2464 Random Line Segment Container Problem which I had to create to detect when a ball enters a line segment:
Code: (Select All)
' return count of how many points overlap segment
Function lineSegIntersectCircle (x1, y1, x2, y2, cx, cy, r)
' x1, y1 and x2, y2 are end points of line segment
' cx, cy are circle center with radius r
Dim rtn, i
Dim As Double d, dx, dy, x, y
d = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
dx = (x2 - x1) / d
dy = (y2 - y1) / d
For i = 0 To d ' this effectively redraws the line point by point without actually drawing it on screen
x = x1 + dx * i
y = y1 + dy * i
If Sqr((x - cx) ^ 2 + (y - cy) ^ 2) <= r Then rtn = rtn + 1
'if this point is in radius range then it is in intersection of circle and line segment
Next
lineSegIntersectCircle = rtn
End Function
b = b + ...