#include #include float inf = 1.0e10; float eps = 0.001; int nsph; struct { float x, y, dx, dy; } ray; typedef struct { float x, y, r; } SPHERE; SPHERE sp[25]; float hit(SPHERE s) { float a, b, c, diskr, t1, t2; a = ray.dx*ray.dx + ray.dy*ray.dy; b = 2*(ray.dx*(ray.x-s.x)+ray.dy*(ray.y-s.y)); c = (ray.x-s.x)*(ray.x-s.x)+(ray.y-s.y)*(ray.y-s.y)-s.r*s.r; diskr = b*b - 4*a*c; if (diskr > 0) { t1 = (-b - sqrt(diskr))/2/a; t2 = (-b + sqrt(diskr))/2/a; if (t1 > eps) return(t1); if (t2 > eps) return(t2); } return(inf); } void getsp(int *s, float *t) { int i; float tt; *t = inf; for (i=0; i