|
|
back to boardWA#5 Can somebody give me test cases or just tell me what is the problem in my program: #include <iostream> #include <cmath> using namespace std; struct vector { double x; double y; double z; }; double dist(vector a, vector b) { double d = sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2) + pow(b.z - a.z, 2)); return d; } double find_d(vector v_normal, vector point) { double minus_d = v_normal.x*point.x + v_normal.y * point.y + v_normal.z * point.z; return -minus_d; } int main(int argc, char * argv[]) { vector C, N, S, V; double R; cin >> C.x >> C.y >> C.z; cin >> N.x >> N.y >> N.z; cin >> R; cin >> S.x >> S.y >> S.z; cin >> V.x >> V.y >> V.z; double t1, t2; double D = find_d(N, C); t1 = (double)(N.x * V.x + N.y * V.y + N.z * V.z - sqrt(20 * N.z * (D + N.x * S.x + N.y * S.y + N.z * S.z) + pow(N.x*V.x+N.y*V.y + N.z*V.z, 2))) / (double)(10.0*N.z); t2 = (double)(N.x * V.x + N.y * V.y + N.z * V.z + sqrt(20 * N.z * (D + N.x * S.x + N.y * S.y + N.z * S.z) + pow(N.x*V.x + N.y*V.y + N.z*V.z, 2))) / (double)(10.0 * N.z); vector hit1, hit2; hit1.x = S.x + t1*V.x; hit1.y = S.y + t1*V.y; hit1.z = S.z + t1*V.z - 5*t1*t1; hit2.x = S.x + t2*V.x; hit2.y = S.y + t2*V.y; hit2.z = S.z + t2*V.z - 5 * t2*t2; if (t1 >= 0) { if (dist(hit1, C) <= R) { cout << "HIT"; return 0; } } if (t2 >= 0) { if (dist(hit2, C) <= R) { cout << "HIT"; return 0; } } cout << "MISSED"; return 0; } |
|
|