0

I am coding a tool that enables to draw polygons. I want them to be simple polygons and forbid drawing complex polygons.

I have tried ToSubpathPolygons()

I have the list of QPoints that form the polygon.

I am coding in c++ + Qt. I think I could try with segment intersections and if there is an intersection it is not simple.

I thought qpainterpath tosubpathPolygons should give me more than one if it is a complex polygon. The problem should be something like this:

if(q.toSubpathPolygons().length()==1)
{
//whatever
}
else{
    cout<<"not a polygon"<<endl;
}
P.Perez
  • 9
  • 4
  • what do you mean with "this function doesn't seem to work properly"? often thinking the problem is somewhere else but not in your code just makes it harder to solve it. Rather unlikely that it is broken and noone noticed before, no? Please provide a [mcve] – 463035818_is_not_an_ai Apr 26 '17 at 18:05
  • That is not the problem, i have tried to subpathpolygons but I think this is not the way to solve the problem – P.Perez Apr 26 '17 at 18:11
  • Your question is not clear, you could ask something concrete. – eyllanesc Apr 26 '17 at 18:16
  • What is a simple polygon? – eyllanesc Apr 26 '17 at 18:16
  • https://www.google.es/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwjHzq3d3sLTAhUFORoKHe1vCxAQjRwIBw&url=http%3A%2F%2Fwww.personal.kent.edu%2F~rmuhamma%2FCompgeometry%2FMyCG%2FDefinitions%2Fdefinition.htm&psig=AFQjCNEXpCkeHPq2a0FPpGoq5Fp2iHZ_rQ&ust=1493317332606474 – P.Perez Apr 26 '17 at 18:23
  • if thats not the problem, then what is the problem? simply follow the definition and check if any of the lines intersect – 463035818_is_not_an_ai Apr 26 '17 at 18:24
  • How can I know if any of them intersect? – P.Perez Apr 26 '17 at 18:25
  • @P.Perez, I can suggest linear algorithm, which can check whether polygon (with one countour) is simple. Is this sufficient for you? – Alex Aparin Apr 26 '17 at 18:30
  • I think that would be perfect – P.Perez Apr 26 '17 at 18:32
  • read this: http://stackoverflow.com/questions/4001745/testing-whether-a-polygon-is-simple-or-complex – eyllanesc Apr 26 '17 at 18:34

0 Answers0