matrix_type orientation(iterator_t point_begin, iterator_t point_end, point_t& center) const { matrix<value_type, N, N> orientation; value_type tightest_volume = boost::numeric::bounds<value_type>::highest(); for (int k = 0; k != _iterations; ++k) { matrix<value_type, N, N> random; point_t dir1 = generate_random_point(); point_t dir2 = generate_random_point(); point_t dir3 = generate_random_point(); // use ortho-normal system dir1 /= dir1.length(); dir2 /= dir2.length(); dir3 /= dir3.length(); // normalize dir3 = cross(dir1, dir2); dir2 = cross(dir1, dir3); random[0][0] = dir1[0]; random[1][0] = dir1[1]; random[2][0] = dir1[2]; random[0][1] = dir2[0]; random[1][1] = dir2[1]; random[2][1] = dir2[2]; random[0][2] = dir3[0]; random[1][2] = dir3[1]; random[2][2] = dir3[2]; // compute volume according to temporary orientation point_t low, high; limits(point_begin, point_end, center, random, low, high); oriented_boundingbox<point_t> obb(random, center, low, high); value_type volume = obb.volume(); // if tighter, apply if (volume < tightest_volume) { orientation = random; tightest_volume = volume; } } return orientation; }
/* * Generates points the unit square for the number of seconds provided by the command line. * Calculates the number of points that fall inside the unit circle and updates global * variables accordingly. */ void* generate_points(void *x) { double total = 0; double inside = 0; // Run program for provided number of seconds time_t start, end; double elapsed; start = time(NULL); end = time(NULL); while(1) { end = time(NULL); elapsed = difftime(end, start); if (elapsed >= seconds) break; // generate point and check distance from center double* z = generate_random_point(); double distance = get_distances(z[0], z[1]); total++; if (distance <= 1) inside++; } // Update global variables pthread_mutex_lock(&lock); total_all += total; inside_all += inside; pthread_mutex_unlock(&lock); return x; }