Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <chrono>
- #include <boost/geometry.hpp>
- #define SIZE_DOUBLE 65535
- int main() {
- auto myarray = new double[SIZE_DOUBLE][3]();
- double startd = 1.0;
- for(int t=0; t!=SIZE_DOUBLE; t++) {
- myarray[t][0] = startd;
- myarray[t][1] = 1.0;
- myarray[t][2] = 1.0;
- startd += 1.0;
- }
- std::cout << "mine ...\n\n\n" << std::endl;
- std::chrono::time_point<std::chrono::system_clock> start_time = std::chrono::system_clock::now();
- double cpoint[3], *mpoint;
- cpoint[0] = 6.0; cpoint[1] = 2.0; cpoint[2] = 1.0;
- double min_d = 65535;
- for(int t=0; t!=SIZE_DOUBLE; t++) {
- double d = std::pow((myarray[t][0]-cpoint[0]), 2) + std::pow((myarray[t][1]-cpoint[1]), 2)
- + std::pow((myarray[t][2]-cpoint[2]), 2) ;
- if (d < min_d) {
- min_d = d;
- mpoint = myarray[t];
- }
- }
- std::chrono::time_point<std::chrono::system_clock> end_time = std::chrono::system_clock::now();
- std::cout << "Closest: (" << mpoint[0] << "," << mpoint[1] << "," << mpoint[2] << ")" << std::endl
- << "At: " << std::sqrt( std::pow((mpoint[0]-cpoint[0]), 2) +
- std::pow((mpoint[1]-cpoint[1]), 2) + std::pow((mpoint[2]-cpoint[2]), 2) ) << std::endl
- << "In: " << std::chrono::duration_cast<std::chrono::milliseconds>
- (end_time - start_time).count() << " milliseconds" << std::endl;
- std::cout << "\n\n\nboost ...\n\n\n" << std::endl;
- std::chrono::time_point<std::chrono::system_clock> start_time2 = std::chrono::system_clock::now();
- typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> mypoint;
- mypoint p, pv, min_p;
- boost::geometry::assign_values(p, 6.0, 2.0, 1.0);
- double min_d2 = 65535;
- for(int t=0; t!=SIZE_DOUBLE; t++) {
- boost::geometry::assign_values(pv, myarray[t][0], myarray[t][1], myarray[t][2]);
- double d = boost::geometry::comparable_distance(p, pv);
- if (d < min_d2) {
- min_d2 = d;
- min_p = pv;
- }
- }
- std::chrono::time_point<std::chrono::system_clock> end_time2 = std::chrono::system_clock::now();
- std::cout
- << "Closest: " << boost::geometry::dsv(min_p) << std::endl
- << "At: " << boost::geometry::distance(p, min_p) << std::endl
- << "In: " << std::chrono::duration_cast<std::chrono::milliseconds>
- (end_time2 - start_time2).count() << " milliseconds" << std::endl;
- std::cin.get();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement