View Full Version : I need to program a test for polygonal convexity

11-11-2003, 02:17 PM
I've just started programming in OpenGL. For my first program I need to create a polygon by clicking the mouse in the window. Each left-click adds a vertex, when I'm done clicking, I hit enter and the program displays the program. This portion I have working already. I just store the values of the vertices in a 3 dimensional array, the figure is 2d. How do I go about coding a test to determine if the polygon is convex or not?

11-11-2003, 02:25 PM
If the polygon is defined by edges E1, E2,...En;

E1 X E2, E2 X E3,... En-1 X En all should point in the same direction (either up from the polygon or down ... assuming the polygon is planer.. contained in a single plane.)

- Chetan

11-11-2003, 03:16 PM
Could you elaborate please? I'm unsure as to what you mean.

11-11-2003, 04:24 PM
asuming your vertexs are (x1,y1,z1),(x2,y2,z2),(x3,y3,z3),(x...,y...,z...) and all the z coords are the same, then
n should be + or - depending if the points are convex or concave or will be 0 if in a streight line
email me if it dosnt work, I wrote this from memory email address is fuz_king@yahoo.co.nz

11-11-2003, 05:56 PM
Check that the dot products of each line pair in the sequence have the same sign, make sure you check the boundary condition.

11-12-2003, 09:17 AM
What is the dot product?

11-12-2003, 11:39 AM
the dot product is just a multiplication of the coordinates of each point, for example u=(u1,u2,u3...un) v=v1,v2,v3...vn) thus the dot product would be
u . v = (u1v1+u2v2+u3v3...unvn)