for(int i=0; i<N; ++i) { float detection = dot(p[i]-a, n); if (detection <= r[i]) { // ... collision response } }