简体   繁体   中英

How to check if the Polygon is Concave or Convex?using openGL

How to check if the Polygon is concave or convex?using openGL. I take points as input from .txt file and I draw with these points a polygon then here comes the problem .. I need an algorithm to detect the type of the polygon .. concave or convex .

void drawPoints() {
glClear(GL_COLOR_BUFFER_BIT); //Clear display window.
if (points.size()<2) {
   glPointSize(3.0);
   glBegin(GL_POINTS);
}
else {
   glLineWidth(3.0);
   glBegin(GL_LINE_LOOP);
}


   for (int i = 0; i<(int)points.size(); i++) {
   Point& p_i = points[i];
   glVertex2f(p_i.GetX(), p_i.GetY());
}



glEnd();
glFlush(); //Process all OpenGL routines as quickly as possible.

}

How to check if the Polygon is concave or convex?

A polygon is defined to be convex if for any line that's being drawn between any two vertices none of the points of the lines comes to happen outside the (filled part) of the polygon. This is a generalization of the definition of convexity of a set.

So how do you test this? The usual approach is determining the convex hull of the polygon (eg with the Gift Wrapping algorithm ) and then test if all edges of the polygon happen to coincide with its convex hull.

using openGL

Not. OpenGL just draws things. It is not meant for processing geometry (beyond what's required for drawing it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM