View Full Version : Filled Convex Polygons
03-24-2003, 06:01 AM
I just finished writing a 3D utility to allow users to define flat polygon outlines using the mouse. Unfortunately, polygon fill doesn't work properly if you have a 'concave' polygon (try it with a U or S shaped surface and you'll see).
What is the simplest solution (besides making the polygons convex)? I want to be able to remedy this in code, without user interaction.
03-24-2003, 06:46 AM
You have to tesselate your polygon yourself : OpenGL only accepts convex polygons.
Fire up google and try searching concave polygon tesselation, or concave polygon triangulation.
03-24-2003, 06:50 AM
I just finished doing just that. I guess I'll create a tesselation object using GLU, and go with that for now.
Is there any OpenGL support for detecting a polygon is 'concave'? (if my program knew it had a convex poly it wouldn't have to tesselate).
03-24-2003, 11:39 AM
You could use cross product of p1p2 and p2p3 vectors formed by points. First set detemine signage. Then successively go through points (p2p3 and p3p4, p3p4 and p4p5, etc) until reaching initial point. If signage of first is positive then any that are less than zero means concave. Zero should be valid because it implies straight line. If signage of first is negative then any that are greater than zero are concave.
Personally, I'd just tesselate them but it depends on your needs and all that.
Should be cross product not dot product. Sorry about that. And positive vs negative is relative to the plane in which polygon lies.
[This message has been edited by shinpaughp (edited 03-24-2003).]
03-24-2003, 05:56 PM
Yes, I'll probably just tesselate for now, and try some speed tests later (if it 'might' speed things up). Usually, if the item changes infrequently, a display list will negate any speed difference during redraws.
Still, it's good to know 'how' to check if tesselation is necessary, and I will put this info in my 'bag of tricks'. Much thanks - SteveH
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.