diff --git a/test/test_find_vol.cpp b/test/test_find_vol.cpp index 6fca504..af2251a 100644 --- a/test/test_find_vol.cpp +++ b/test/test_find_vol.cpp @@ -8,6 +8,15 @@ using namespace double_down; +void sample_dir(double p[3]) { + double mu = -1.0 + 2.0 * (double)std::rand() / (double)RAND_MAX; + double phi = 2.0 * M_PI * (double)std::rand() / (double)RAND_MAX; + double rh = sqrt(1.0 - mu*mu); + p[0] = rh*cos(phi); + p[1] = rh*sin(phi); + p[2] = mu; +} + int main() { // create new MOAB instance @@ -30,13 +39,10 @@ int main() { moab::EntityHandle sphere_vol = vols[0]; // fire a test ray - double org[3] = {0.0, 0.0, 0.0}; - double dir[3] = {1.0, 0.0, 0.0}; + double org[3] {0.0, 0.0, 0.0}; + double dir[3] {1.0, 0.0, 0.0}; - double dist = 0.0; - moab::EntityHandle surf; for (int i = 0; i < 1000; i++) { - std::cout << org[0] << " " << org[1] << " " << org[2] << std::endl; moab::EntityHandle volume = 0; RTI->find_volume(org, volume, dir); if (volume != sphere_vol) { return 1; } @@ -46,13 +52,11 @@ int main() { RTI->find_volume(org, volume); if (volume != sphere_vol) { return 1; } - // sample a random point in the sphere volume - double mu = -1.0 + 2.0 * (double)std::rand() / (double)RAND_MAX; - double phi = 2.0 * M_PI * (double)std::rand() / (double)RAND_MAX; + // sample a new position and direction for subsequent checks double r = 9.9 * (double)std::rand() / (double)RAND_MAX; - org[0] = sqrt(1-mu*mu)*cos(phi)*r; - org[1] = sqrt(1-mu*mu)*sin(phi)*r; - org[2] = r*mu; + sample_dir(org); + for (auto& val : org) { val *= r; } + sample_dir(dir); } return 0;