SHARE
TWEET

Untitled

daniil_mironoff Nov 25th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. struct dot {
  7.     int X;
  8.     int Y;
  9.     int Z;
  10. };
  11.  
  12. double findMinDist(dot* arr, unsigned int size) {
  13.     unsigned int v1 = pow(arr[0].X - arr[1].X, 2);
  14.     unsigned int v2 = pow(arr[0].Y - arr[1].Y, 2);
  15.     unsigned int v3 = pow(arr[0].Z - arr[1].Z, 2);
  16.  
  17.     double min = sqrt(v1 + v2 + v3);
  18.     for (unsigned int i = 0; size - 1 > i; i++) {
  19.         for (unsigned int k = i + 1; size > k; k++) {
  20.             v1 = pow(arr[i].X - arr[k].X, 2);
  21.             v2 = pow(arr[i].Y - arr[k].Y, 2);
  22.             v3 = pow(arr[i].Z - arr[k].Z, 2);
  23.  
  24.             double val = sqrt(v1 + v2 + v3);
  25.             if (val < min) { min = val; }
  26.         }
  27.     }
  28.  
  29.     return min;
  30. }
  31.  
  32. const unsigned int COUNT_DOT = 10000;
  33.  
  34. int main() {
  35.     dot arr_dot[COUNT_DOT];
  36.  
  37.     for (unsigned int i = 0; COUNT_DOT > i; i++) {
  38.         cout << "Enter X Y Z: ";
  39.         cin >> arr_dot[i].X >> arr_dot[i].Y >> arr_dot[i].Z;
  40.     }
  41.  
  42.     cout.setf(ios::scientific);
  43.     cout << "Result: " << findMinDist(arr_dot, COUNT_DOT) << endl;
  44.    
  45.    
  46.  
  47.     return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top