Advertisement
Guest User

Untitled

a guest
Mar 25th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <math.h>
  8.  
  9. using namespace std;
  10.  
  11. int MaxPt= 0;
  12.  
  13. struct CoordUser
  14. {
  15. // координаты
  16. double x;
  17. double y;
  18. double z;
  19. // вектор расстояния
  20. double v;
  21. // количество соседей
  22. int n;
  23. };
  24.  
  25. bool Compare(struct CoordUser bsL, struct CoordUser bsR)
  26. {
  27. return bsL.n > bsR.n;
  28. }
  29.  
  30. class Sphera
  31. {
  32. public:
  33. struct CoordUser cu;
  34. vector < struct CoordUser > vcu;
  35. double r;
  36.  
  37. Sphera (double *pt, const int p)
  38. {
  39. cout << "Введите радиус сферы = "; cin >> r;
  40. int pp= 0;
  41. while (pp < p)
  42. {
  43. cu.x= pt[pp]; pp++;
  44. cu.y= pt[pp]; pp++;
  45. cu.z= pt[pp]; pp++;
  46. cu.v= 0.0;
  47. cu.n= 0;
  48. vcu.push_back(cu);
  49. }
  50. }
  51. ////////////
  52. void PrintCoord() // Для контроля информации входной
  53. {
  54. cout << left << setw(10) << "Xcoord";
  55. cout << left << setw(10) << "Ycoord";
  56. cout << left << setw(10) << "Zcoord";
  57. cout << left << setw(10) << "Vector";
  58. cout << left << setw(10) << "Соседи" << endl;
  59. cout << setw(50) << setfill('=') << "=" << setfill(' ') << endl;
  60.  
  61. int pp= 0;
  62. while (pp < vcu.size())
  63. {
  64. cu= vcu[pp];
  65. cout << setw(10) << left << cu.x;
  66. cout << setw(10) << left << cu.y;
  67. cout << setw(10) << left << cu.z;
  68. cout << setw(10) << left << cu.v;
  69. cout << setw(10) << left << cu.n << endl;
  70. pp++;
  71. }
  72. }
  73. /////////////
  74. void FindPtCnt()
  75. {
  76. struct CoordUser lf= vcu[0]; struct CoordUser rt;
  77. int p1= 0;
  78. while (p1 < vcu.size())
  79. {
  80. rt= vcu[p1];
  81. if (lf.n == rt.n) MaxPt++;
  82. p1++;
  83. }
  84. }
  85. /////////////
  86. void FuncUser()
  87. {
  88. struct CoordUser lf, rt;
  89. int p0= 0; int p1;
  90.  
  91. while (p0<vcu.size())
  92. {
  93. p1= 0; lf= vcu[p0];
  94. while (p1 < vcu.size())
  95. {
  96. if (p1!=p0)
  97. {
  98. rt= vcu[p1];
  99. double v= sqrt( pow((rt.x-lf.x),2.0) + pow((rt.y-lf.y),2.0) + pow((rt.z-lf.z),2.0) );
  100. if (v<r) lf.n++;
  101. }
  102. vcu[p0]= lf;
  103. p1++;
  104. }
  105. p0++;
  106. }
  107. sort(vcu.begin(), vcu.end(), Compare);
  108. cout << endl << endl;
  109. PrintCoord();
  110.  
  111. FindPtCnt(); p0= 0;
  112.  
  113. cout << endl << endl;
  114.  
  115. while(p0 < MaxPt)
  116. {
  117. lf= vcu[p0];
  118. cout << "Центр шара возможен в точке X" << lf.x << " Y" << lf.y << " Z" << lf.z << endl;
  119. p0++;
  120. }
  121. }
  122. };
  123. int main(int argc, char **argv)
  124. {
  125. system("chcp 1251 > nul"); // Руссификация сообщений
  126. setlocale(LC_ALL, "Russian");
  127.  
  128. const int pt3D= 30;
  129. double crd[pt3D]= {
  130. 7.24, 1.94, 10.15,
  131. -2.71, -9.72, 10.0,
  132. 8.51, 2.48, 10.15,
  133. -2.18, -5.72, 0.0,
  134. 7.59, -2.45, -1.85,
  135. -6.86, -10.71, -10.4,
  136. 3.35, 3.43, 10.51,
  137. -1.74, 0.0, 0.0,
  138. -2.25, 8.24, -1.95,
  139. -6.81, -9.83, 2.0
  140. };
  141.  
  142. Sphera s(crd, pt3D); s.PrintCoord(); s.FuncUser();
  143.  
  144. system("pause"); // system("pause > nul");
  145. return 0;
  146. }
  147.  
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement