12,689,801 members (24,495 online)
alternative version

173.3K views
21 bookmarked
Posted

# Tesselation of Mono Connected Non Convex Polygon

, 6 Feb 2002 CPOL
 Rate this:
Tesselation of mono connected non convex polygon

## Introduction

A simple alternative to OpenGL polygon tesselation callback. You can focus on file triangle.h that contain the class to evaluate convexity of polygon and tesselate the polygon. No extra points are inserted. You can work only with planar polygon also in 3D.

Every suggestion in order to speed up the class and create better tesselation ('better' triangles) is appreciated.

## History

• 6th February, 2002: Initial post

## About the Author

 United States
No Biography provided

## Comments and Discussions

 First Prev Next
 cut object in slicing joy_nim24-Feb-06 7:01 joy_nim 24-Feb-06 7:01
 Possible error and fix GregDude21-Jul-05 16:34 GregDude 21-Jul-05 16:34
 I found this routine sometimes produces incorrect tesselation. When certain points in the polygon winding are colinear, it can skip over them and produce triangles outside of the original polygon. My fix simply classifies points on the edge of the test triangle as 'inside' instead of 'outside'. This appears to be a stable and beneficial fix so far.Example Input:```poly normal (0.000f,-0.500f,0.866f) poly points (0.700f,6.500f,4.071f) // 0 (0.700f,5.500f,3.494f) // 1 This point gets mis-classified with 2,8,9 triangle (-1.700f,5.500f,3.494f) // 2 (-1.700f,6.500f,4.071f) // 3 (-2.500f,6.500f,4.071f) // 4 (-7.300f,1.700f,1.300f) // 5 (11.300f,1.700f,1.300f) // 6 (7.500f,5.500f,3.494f) // 7 (4.300f,5.500f,3.494f) // 8 (4.300f,6.500f,4.071f) // 9 ```Old Code in function IsPointInside():```pmq2.Vector(m_e1,ntmp); if( (B0=m_N.Dot(ntmp)) <= 0.0 ) return false; m_e0.Vector(pmq2,ntmp); if( (B1=m_N.Dot(ntmp)) <= 0.0 ) return false; return ( (m_A-B0-B1) > 0.0 ? true : false ); ```New Code:```pmq2.Vector(m_e1,ntmp); if( (B0=m_N.Dot(ntmp)) < 0.0 ) return false; m_e0.Vector(pmq2,ntmp); if( (B1=m_N.Dot(ntmp)) < 0.0 ) return false; return ( (m_A-B0-B1) < 0.0 ? false : true); ```Helpful explaination of internal variables:```//...........^..... //.........I/...... //.N......./....... //.^...e0./........ //.|...../__-->p... //.|...K.\......... //........\...A.... //......e1.\....... //..........\...... //...........v..... //..........J...... //(I replaced spaces with dots as they were not preserved in post?) // // I,J,K (points of current test triangle, indices or indirect indices) // e0,e1 (edges from IK, JK) // A (Area of current triangle, is actually area*2) // N (Normal of current triangle, not unit length) // // p Test point if in current triangle. // ```Edit....Further testing shows that neither the old or new code correctly and consistently handles coincident and colinear points. (Eg. An example of a coincident point, is a Figure '8' polygons that does not actually cross over, just converges in the middle.)Example Input:```// Eg. Coincident point, figure 8 style poly normal (0.000f,-0.500f,0.866f) poly points (1.700f,6.300f,2.801f) (4.300f,3.700f,1.300f) (5.700f,3.700f,1.300f) (7.000f,5.000f,2.051f) (8.300f,3.700f,1.300f) (9.300f,3.700f,1.300f) (8.000f,5.000f,2.051f) (7.000f,5.000f,2.051f) (1.700f,10.300f,5.111f) ```This should help more with coincident points:Old code in IsAnyPointInside():```if( ( ip < i || ip > k ) && IsPointInside(points[m_nIndex[ip]],points[ik]) ) { return true; } ```New code:```if( ip < i || ip > k ) { // NOTE: This is Vector3 exact equality test if( points[m_nIndex[ip]].Equal(points[m_nIndex[i]]) || points[m_nIndex[ip]].Equal(points[m_nIndex[j]]) || points[m_nIndex[ip]].Equal(points[m_nIndex[k]]) ) { continue; // Identical points are not inside, they do not hurt turns } if( IsPointInside(points[m_nIndex[ip]],points[ik]) ) { return true; } } ```If topus's suggested change is valid, it should read```// // j is alligned from i to k ? // if( ((-FLT_EPSILON) < m_A && m_A < FLT_EPSILON) || // Area OR Poor Normal ((-FLT_EPSILON) < m_N[0] && m_N[0] < FLT_EPSILON && (-FLT_EPSILON) < m_N[1] && m_N[1] < FLT_EPSILON && (-FLT_EPSILON) < m_N[2] && m_N[2] < FLT_EPSILON )) return degenerate; // NOTE: This code is more efficient on PC with eg. 'fabsf(m_A) <= FLT_EPSILON' to reduce float compares. ```Also note that you can help the algorithm by removing 'junk' before processing. Eg. project 3D points onto plane (of which normal is used). Remove degeneracies like coincident and colinear points. Snapping and merging points may help, but could lead to bad-snaps that cause self intersections.Edit:I have found another case which I believe shows a flaw in the algorithm. As 'ears' are clipped off the polygon, the remaining polygon can become self intersecting and fail 'point in poly' test, to produce triangles outside the original shape.Example input:```poly normal(0,0,1) (10.52881622f,-1.25890017f,0.00000000f) (10.52881241f,0.24110639f,0.00000000f) (-1.47119045f,0.24110317f,0.00000000f) (-1.47119141f,-1.25889719f,0.00000000f) (4.52881575f,-1.25890088f,0.00000000f) (4.52881479f,-3.25889254f,0.00000000f) (6.08583260f,-3.25889111f,0.00000000f) (6.08583069f,-1.25889945f,0.00000000f) ```The fix:in function Triangulate()in 'case convex :'in else, after 'RemoveVertex'```// Advance to preserve poly integrity i = j; j = k; k++; ```This allows the point AFTER the removed triangle point to be the start of the next test triangle. This helps with near colinear points that fan out from an otherwise stationary start point.Edit:There are still issues with the code. The bottom line is that the original algorithm does not handle simple non-covex polys with colinear, but non intersecting segments. The overall algorithm does not handle polygons that intersect in anyway, including at single points, though it often produces a correct or near correct result.Please comment on this.
 Robust tesselation Skavenger1-Jul-05 23:04 Skavenger 1-Jul-05 23:04
 Re: Robust tesselation [modified] Liu Guoping9-Aug-06 16:51 Liu Guoping 9-Aug-06 16:51
 Re: Robust tesselation Skavenger310-Aug-06 2:42 Skavenger3 10-Aug-06 2:42
 Problem in CPolyTri::ComputeNormal Torsten B8-Jun-04 2:43 Torsten B 8-Jun-04 2:43
 Re: Problem in CPolyTri::ComputeNormal Sebastien Maraux13-Dec-04 4:52 Sebastien Maraux 13-Dec-04 4:52
 Re: Problem in CPolyTri::ComputeNormal Sébastien Maraux14-Dec-04 0:45 Sébastien Maraux 14-Dec-04 0:45
 Good Article mchapman123422-May-04 12:50 mchapman1234 22-May-04 12:50
 Found an index range error in code TruePyroman23-Feb-03 15:38 TruePyroman 23-Feb-03 15:38
 Re: Found an index range error in code topus10-Apr-03 3:46 topus 10-Apr-03 3:46
 Better tesselation jeckle8-Feb-02 10:00 jeckle 8-Feb-02 10:00
 Re: Better tesselation pepito10-Feb-02 23:05 pepito 10-Feb-02 23:05
 Re: Better tesselation jeckle11-Feb-02 11:46 jeckle 11-Feb-02 11:46
 Re: Better tesselation Rick York11-Feb-02 11:53 Rick York 11-Feb-02 11:53
 Better tesselation Tim Aidley8-Feb-02 3:45 Tim Aidley 8-Feb-02 3:45
 Re: Better tesselation kilowatt8-Feb-02 9:21 kilowatt 8-Feb-02 9:21
 Re: Better tesselation pepito sbarzeguti10-Feb-02 23:03 pepito sbarzeguti 10-Feb-02 23:03
 Guareschiano anche tu? Anonymous7-Feb-02 22:19 Anonymous 7-Feb-02 22:19
 Re: Guareschiano anche tu? Dieter Hammer8-Feb-02 1:04 Dieter Hammer 8-Feb-02 1:04
 Re: Guareschiano anche tu? pepito8-Feb-02 2:38 pepito 8-Feb-02 2:38
 Re: Guareschiano anche tu? Anonymous10-Feb-02 23:37 Anonymous 10-Feb-02 23:37
 Very poor article on very interesting subject... George7-Feb-02 15:25 George 7-Feb-02 15:25
 Re: Very poor article on very interesting subject... Pepito Sbarzeguti7-Feb-02 22:46 Pepito Sbarzeguti 7-Feb-02 22:46
 Re: Very poor article on very interesting subject... Anonymous7-Feb-02 22:47 Anonymous 7-Feb-02 22:47
 Re: Very poor article on very interesting subject... Andy Metcalfe8-Feb-02 0:14 Andy Metcalfe 8-Feb-02 0:14
 Re: Very poor article on very interesting subject... Anonymous10-Feb-02 0:26 Anonymous 10-Feb-02 0:26
 Re: Very poor article on very interesting subject... George10-Feb-02 0:53 George 10-Feb-02 0:53
 Re: Very poor article on very interesting subject... Nish [BusterBoy]10-Feb-02 1:21 Nish [BusterBoy] 10-Feb-02 1:21
 Re: Very poor article on very interesting subject... Mazdak10-Feb-02 2:02 Mazdak 10-Feb-02 2:02
 Re: Very poor article on very interesting subject... Nish [BusterBoy]10-Feb-02 2:04 Nish [BusterBoy] 10-Feb-02 2:04
 Re: Very poor article on very interesting subject... Anonymous10-Feb-02 16:33 Anonymous 10-Feb-02 16:33
 Re: Very poor article on very interesting subject... Nish [BusterBoy]10-Feb-02 17:32 Nish [BusterBoy] 10-Feb-02 17:32
 Is the artical "fill in the blank"? Jason De Arte7-Feb-02 14:57 Jason De Arte 7-Feb-02 14:57
 Re: Is the artical "fill in the blank"? Nish [BusterBoy]8-Feb-02 0:13 Nish [BusterBoy] 8-Feb-02 0:13
 Why? Anonymous7-Feb-02 12:24 Anonymous 7-Feb-02 12:24
 Re: Why? asim_u7-Feb-02 12:57 asim_u 7-Feb-02 12:57
 Re: Why? Josh Knox8-Feb-02 6:48 Josh Knox 8-Feb-02 6:48
 Re: Why? Anonymous8-Aug-02 8:55 Anonymous 8-Aug-02 8:55
 Re: Why? Gernot20-Aug-02 3:09 Gernot 20-Aug-02 3:09
 Last Visit: 31-Dec-99 19:00     Last Update: 16-Jan-17 10:05 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.