#include "glut.h" #include #include #include #include #include #include using namespace std; int *x; int *y; vector parts; int n; int point(int next,int q,int i){ int a = sqrt((x[i]-x[q])*(x[i]-x[q])+(y[i]-y[q])*(y[i]-y[q])); int b = sqrt((x[i]-x[next])*(x[i]-x[next])+(y[i]-y[next])*(y[i]-y[next])); if(b= 0; -- i) if (x[i] != x[q] || y[i] != y[q]) { sign = 0.5 * (x[next] * y[q] + x[q] * y[i] + x[i] * y[next] - y[next] * x[q] - y[q] * x[i] - y[i] * x[next]); if (next == q || sign > 0 || (sign == 0 && point(next, q, i))) next = i; } q = next; } while(q!=first); int d; cout << endl << "Точки выпуклой оболочки:" << endl; for (vector::iterator it = parts.begin() ; it!=parts.end() ; ++it){ d=*it; cout<::iterator it = parts.begin() ; it!= parts.end(); it++) { glColor3f(1, 0, 0); glVertex2f(x[*it], y[*it]); } glEnd(); glColor3f(1, 1, 1); for (int i = 0; i < n; i++) { glBegin(GL_TRIANGLE_FAN); glVertex2f(x[i], y[i]); float r = 5; for (float phi = 0; phi <= 6.30; phi += 0.1) { float x0 = r * cos(phi); float y0 = r * sin(phi); glVertex2f(x0 + x[i], y0 + y[i]); } glEnd(); } glutSwapBuffers(); } int main(int argc, char **argv){ setlocale(LC_ALL,"Rus"); cout << "Алгоритм Джарвиса:" << endl; cout << "Количество точек на плоскости: "; cin >> n; x = new int [n]; y = new int [n]; srand(time(NULL)); for(int i = 0; i < n; i++){ x[i]=rand()%550+30; y[i]=rand()%350+30; } for(int i = 0; i < n; i++){ cout<