Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- using namespace std;
- int MaxPt= 0;
- struct CoordUser
- {
- // координаты
- double x;
- double y;
- double z;
- // вектор расстояния
- double v;
- // количество соседей
- int n;
- };
- bool Compare(struct CoordUser bsL, struct CoordUser bsR)
- {
- return bsL.n > bsR.n;
- }
- class Sphera
- {
- public:
- struct CoordUser cu;
- vector < struct CoordUser > vcu;
- double r;
- Sphera (double *pt, const int p)
- {
- cout << "Введите радиус сферы = "; cin >> r;
- int pp= 0;
- while (pp < p)
- {
- cu.x= pt[pp]; pp++;
- cu.y= pt[pp]; pp++;
- cu.z= pt[pp]; pp++;
- cu.v= 0.0;
- cu.n= 0;
- vcu.push_back(cu);
- }
- }
- ////////////
- void PrintCoord() // Для контроля информации входной
- {
- cout << left << setw(10) << "Xcoord";
- cout << left << setw(10) << "Ycoord";
- cout << left << setw(10) << "Zcoord";
- cout << left << setw(10) << "Vector";
- cout << left << setw(10) << "Соседи" << endl;
- cout << setw(50) << setfill('=') << "=" << setfill(' ') << endl;
- int pp= 0;
- while (pp < vcu.size())
- {
- cu= vcu[pp];
- cout << setw(10) << left << cu.x;
- cout << setw(10) << left << cu.y;
- cout << setw(10) << left << cu.z;
- cout << setw(10) << left << cu.v;
- cout << setw(10) << left << cu.n << endl;
- pp++;
- }
- }
- /////////////
- void FindPtCnt()
- {
- struct CoordUser lf= vcu[0]; struct CoordUser rt;
- int p1= 0;
- while (p1 < vcu.size())
- {
- rt= vcu[p1];
- if (lf.n == rt.n) MaxPt++;
- p1++;
- }
- }
- /////////////
- void FuncUser()
- {
- struct CoordUser lf, rt;
- int p0= 0; int p1;
- while (p0<vcu.size())
- {
- p1= 0; lf= vcu[p0];
- while (p1 < vcu.size())
- {
- if (p1!=p0)
- {
- rt= vcu[p1];
- double v= sqrt( pow((rt.x-lf.x),2.0) + pow((rt.y-lf.y),2.0) + pow((rt.z-lf.z),2.0) );
- if (v<r) lf.n++;
- }
- vcu[p0]= lf;
- p1++;
- }
- p0++;
- }
- sort(vcu.begin(), vcu.end(), Compare);
- cout << endl << endl;
- PrintCoord();
- FindPtCnt(); p0= 0;
- cout << endl << endl;
- while(p0 < MaxPt)
- {
- lf= vcu[p0];
- cout << "Центр шара возможен в точке X" << lf.x << " Y" << lf.y << " Z" << lf.z << endl;
- p0++;
- }
- }
- };
- int main(int argc, char **argv)
- {
- system("chcp 1251 > nul"); // Руссификация сообщений
- setlocale(LC_ALL, "Russian");
- const int pt3D= 30;
- double crd[pt3D]= {
- 7.24, 1.94, 10.15,
- -2.71, -9.72, 10.0,
- 8.51, 2.48, 10.15,
- -2.18, -5.72, 0.0,
- 7.59, -2.45, -1.85,
- -6.86, -10.71, -10.4,
- 3.35, 3.43, 10.51,
- -1.74, 0.0, 0.0,
- -2.25, 8.24, -1.95,
- -6.81, -9.83, 2.0
- };
- Sphera s(crd, pt3D); s.PrintCoord(); s.FuncUser();
- system("pause"); // system("pause > nul");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement