Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Am getting "inf" or -0 values for the triangles point ? #4

Closed
GoogleCodeExporter opened this issue Oct 24, 2015 · 3 comments
Closed

Comments

@GoogleCodeExporter
Copy link

Hi,
I am after drawing concave/vex polygons in openGL, and  came across your code, 
which I believe 
might be what I am looking for to break polygons into multiple triangles.

I have the following in my code:

==================
    //Run the polytri to calculate tesslated triangles
    /// Constrained triangles
    vector<Triangle*> triangles;
    vector<p2t::Point*> polyline;
    //For tesselattion cannot have duplicated point = > skip the last
    for (int i = 0; i < (pPolygonPoints->size() -1); ++i)
    {
     polyline.push_back(new Point(*(pPolygonPoints->at(i)->getX()),*(pPolygonPoints->at(i)-
>getY())));
      cout << "gdsPolygonDEBUG: ADDED POINT " << *(pPolygonPoints->at(i)->getX()) << " " << 
*(pPolygonPoints->at(i)->getY())<< flush << endl;
    }

    CDT* cdt = new CDT(polyline);
    cdt->Triangulate();
    triangles = cdt->GetTriangles();
    delete cdt;

    for (int i = 0; i < triangles.size(); i++) {
      Triangle& t = *triangles[i];
      Point& a = *t.GetPoint(0);
      Point& b = *t.GetPoint(1);
      Point& c = *t.GetPoint(2);

      float newX1 = a.x;
      float newY1 = a.y;
      float newX2 = b.x;
      float newY2 = b.y;
      float newX3 = c.x;
      float newY3 = c.y;
      //////////////////////////
      #ifdef gdsPolygonDEBUG
      cout << "gdsPolygonDEBUG: Triangle A : "<< newX1 << " " << newY1 << flush << endl;
      cout << "gdsPolygonDEBUG: Triangle B : "<< newX2 << " " << newY2 << flush << endl;
      cout << "gdsPolygonDEBUG: Triangle C : "<< newX3 << " " << newY3 << flush << endl;
      #endif
      //////////////////////////
    }

==================

When I run, I get the following (note you can see the points I am adding in 
from my classes into 
polyline).

Either the triangle point for "a" come out as inf or -0. Point "a" never seems 
to be getting non-
zero numbers.

Am I using your class incorrectly, or is there as buglet somewhere ?

I hope you can help.

Many thanks in advance

Colin Thomas

===================
gdsPolygonDEBUG: ADDED POINT -1.92 0
gdsPolygonDEBUG: ADDED POINT -1.92 1.92
gdsPolygonDEBUG: ADDED POINT -0.96 1.92
gdsPolygonDEBUG: ADDED POINT -0.96 2.88
gdsPolygonDEBUG: ADDED POINT 5.12 2.88
gdsPolygonDEBUG: ADDED POINT 5.12 -4.16
gdsPolygonDEBUG: ADDED POINT -1.92 -4.16
gdsPolygonDEBUG: ADDED POINT -1.92 -0.96
gdsPolygonDEBUG: ADDED POINT -0.96 -0.96
gdsPolygonDEBUG: ADDED POINT -0.96 0

gdsPolygonDEBUG: Triangle A : 0 0
gdsPolygonDEBUG: Triangle B : -1.92 1.92
gdsPolygonDEBUG: Triangle C : -1.92 0

gdsPolygonDEBUG: Triangle A : 0 0
gdsPolygonDEBUG: Triangle B : -1.92 0
gdsPolygonDEBUG: Triangle C : -0.96 0

gdsPolygonDEBUG: Triangle A : 0 -0
gdsPolygonDEBUG: Triangle B : -0.96 1.92
gdsPolygonDEBUG: Triangle C : -0.96 0

gdsPolygonDEBUG: Triangle A : 0 -0
gdsPolygonDEBUG: Triangle B : -0.96 0
gdsPolygonDEBUG: Triangle C : -0.96 -0.96

gdsPolygonDEBUG: Triangle A : 0 0
gdsPolygonDEBUG: Triangle B : 5.12 -4.16
gdsPolygonDEBUG: Triangle C : 5.12 2.88

gdsPolygonDEBUG: Triangle A : 0 0
gdsPolygonDEBUG: Triangle B : -0.96 -0.96
gdsPolygonDEBUG: Triangle C : -1.92 -4.16

gdsPolygonDEBUG: Triangle A : 0 0
gdsPolygonDEBUG: Triangle B : -1.92 -0.96
gdsPolygonDEBUG: Triangle C : -1.92 -4.16

gdsPolygonDEBUG: Triangle A : 0 -0
gdsPolygonDEBUG: Triangle B : -0.96 2.88
gdsPolygonDEBUG: Triangle C : -0.96 1.92

===================

Original issue reported on code.google.com by ColinPet...@gmail.com on 27 Apr 2010 at 6:15

@GoogleCodeExporter
Copy link
Author

I ran your point set with the testbed demo; see the screenshot for results.  I 
would 
suggest that you check your code again. Maybe you have a pointer error?

Original comment by mason.gr...@gmail.com on 29 Apr 2010 at 11:48

  • Added labels: Type-Other
  • Removed labels: Type-Defect

Attachments:

@GoogleCodeExporter
Copy link
Author

Try moving 'delete cdt' to the very end of your code....

Original comment by mason.gr...@gmail.com on 29 Apr 2010 at 11:52

@GoogleCodeExporter
Copy link
Author

Original comment by mason.gr...@gmail.com on 1 May 2010 at 12:53

  • Changed state: Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant