Polygon rendering question

Try passing the path into a display.newLine function. It should be more obvious where the problem is.

Actually, I have used scanline method to draw the provided vertices. [(Not using newPolygon()]

Attached is the drawn result by scanline method. 

However, this method is not optimized as it needed a lot of line objects which slowed down the app. 

I would like to know the mechanism that corona sdk determine the polygon is self-intersecting. Or can someone helped me to point out the self-intersecting part inside the provided vertices data? Thanks a lot!

oh God, don’t use that - use the display.newPolygon function!

UPDATE: Chris.  You said in your initial post that the shape wasn’t concave, but it definitely is.  Regardless, display.newPolygon() can render convex and concave shapes,  however your shape has edges so close to each other that in all likelihood, you’re getting some overlap due to precision errors.

Your first intersection occurs between the 615th and 616th vertex.  This is NOT a joke, I have a utility to fix this kind of thing (not ready for release to public yet).  However, even if you fix that, this polygon won’t render.  

Honestly, this list is HUGE.  I’m not sure if newPolygon() has ever been tested with such a large list of vertices.  

Also, this is a very complex concave shape.  The turns may simply be so close to each other that, within precision, the polygon rendering code can’t handle it. i.e. Due to precision errors you may be grazing edges.

complexPolygon.png

Yeah, I’m pretty sure that poly path is only like that because it was being used with my old polygon renderer, which is long out of date (not even published) because of the new display.newPolygon - which should be used in this instance. Start there, or we can’t help.

Dear roaminggamer,

  Thanks so much for your precious suggestion. As you said in the post, I cannot get the polygon rendered even I have fixed the problem.

  Since the scanline method is not efficient at all, do you have another way for me to render this kind of polygon? Our app need to render a lot of these polygons and this is a very important feature to our app. (BTW, I would like to use the obj.fill() feature to provide texture of the polygon. By using scanline method I can acheive this. But it is resource impractical.)

Dear horacebury,

  

  I have not only fixed the points suggested by roaminggamer, but also have reduced the vertices set to 20. It is fine with about 10 sets of vertice. After 10 sets, the newPolygon function cannot render. I guess it is the precision problem mentioned by roaminggamer.

  If newPolygon() is not worked in my case, do you have another suggestion? I am planning to upgrade my license. I wonder if I can write my own plugin to handle this problem? Please help me out. This feature is key to our success. Corona is perfect in every corners for my app and just need to tackle this problem.

You need to post your code. Without that we can’t help any more.

Dear horacebury,

  I am sorry. I may not get you very well( I am not native English speaker). You mean the scanline method? Or just the vertices with newPolygon() ?

The following is the reduced vertices version…

vertices = { 698, 98, 695, 97, 685, 98, 682, 99, 679, 100, 676, 101, 673, 104, 670, 104, 668, 103, 666, 103, 664, 103, 664, 102, 661, 101, 660, 100, 660, 99, 659, 99 }

local solidPoly = display.newPolygon(500, 200, vertices )

I just used this code to show where the poly goes wrong:

local vertices = { 698, 98, 695, 97, 685, 98, 682, 99, 679, 100, 676, 101, 673, 104, 670, 104, 668, 103, 666, 103, 664, 103, 664, 102, 661, 101, 660, 100, 660, 99, 659, 99 } local x, y = 400, 100 for i=6, #vertices, 2 do local list = {} for p=1, i do list[p] = vertices[p] end local solidPoly = display.newPolygon( x, y, list ) solidPoly.xScale, solidPoly.yScale = 3, 3 local line = display.newLine( unpack( list ) ) line.x, line.y = x+200, y line.strokeWidth = 2 display.newText{ x=100, y=y, text="#"..i..": "..list[#list-1]..","..list[#list], fontSize=26 } y = y + 50 end

Dear horacebury,

  Thank you so much for your check code. You are right the newPolygon() is working fine after I corrected all points with your check code.

  I would like to know if the newPolygon complained self-intersection, is there any way to detect the polygon cannot render except reading the command prompt for debug purpose? Because in practical use I would like to ask the vertices generator to re-generate the vertices if corona SDK detected self-intersection.

Unfortunately, no, the newPolygon function does not provide any programmatic feedback for when a polygon has failed to render. I think this is a flaw, though it’s definitely not a bug, and I registered a request for feature enhancement a while ago. Feel free to register another.

Just curious, where to find the registered bug/flaw? 

Just using “Report A Bug”, I can ask corona to improve this issue?