Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double triangleArea(punct a, punct b, punct c) {
- return abs((a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)) / 2);
- }
- bool pointInTriangle(punct a, punct b, punct c, punct m) {
- if (triangleArea(a, b, c) == triangleArea(a, b, m) + triangleArea(a, c, m) + triangleArea(b, c, m))
- return true;
- return false;
- }
- void desen() // procedura desenare
- {
- if (p.size() >= 2) {
- glLineWidth(3);
- glBegin(GL_LINES);
- glColor3f(0, 0, 0);
- for (int i = 0; i < p.size() - 1; i++) {
- glVertex2i(p[i].x, p[i].y);
- glVertex2i(p[i + 1].x, p[i + 1].y);
- }
- if (p.size() == n) {
- glVertex2i(p[0].x, p[0].y);
- glVertex2i(p[n - 1].x, p[n - 1].y);
- }
- glEnd();
- if (p.size() == n) {
- int k = 0;
- for (int i = 1; i < p.size(); i++) {
- if (p[k].x > p[i].x)
- k = i;
- }
- glEnable(GL_POINT_SMOOTH);
- glPointSize(10);
- glBegin(GL_POINTS);
- for (int i = 0; i < p.size(); i++) {
- punct v, w, pct;
- if (i == p.size() - 1) {
- v = vect[i];
- w = vect[0];
- pct = p[0];
- }
- else {
- v = vect[i];
- w = vect[i + 1];
- pct = p[i + 1];
- }
- if ((prodVect(v, w).z * prodVect(vect[k == 0 ? vect.size() - 1 : k - 1], vect[k]).z) > 0) {
- int nr = 0;
- punct a, b, c;
- if (i == p.size() - 1) {
- a = p[i];
- b = p[0];
- c = p[1];
- }
- else if (i == p.size() - 2) {
- a = p[i];
- b = p[i + 1];
- c = p[0];
- }
- else {
- a = p[i];
- b = p[i + 1];
- c = p[i + 2];
- }
- for (int j = 0; j < p.size(); j++) {
- if (pointInTriangle(a, b, c, p[j]))
- nr++;
- }
- cout << nr;
- if (nr == 3) {
- vfPrin.push_back(b);
- }
- glColor3f(1, 0, 0);
- }
- else {
- glColor3f(0, 0, 1);
- }
- glVertex2i(pct.x, pct.y);
- }
- glEnd();
- glColor3f(0, 0, 0);
- for (int i = 0; i < vfPrin.size(); i++) {
- glRasterPos2i(vfPrin[i].x + 15, vfPrin[i].y + 15);
- glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, 'P');
- }
- }
- }
- glFlush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement