sp-mishra / poly2tri

Automatically exported from code.google.com/p/poly2tri
Other
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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

Attachments:

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago

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