Skip to content

Commit

Permalink
Sample both position and direction
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise committed Aug 19, 2023
1 parent 4682b2f commit 8085914
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/test_find_vol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }
Expand All @@ -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;
Expand Down

0 comments on commit 8085914

Please sign in to comment.