I have n points that determine a polygon. I need to color the interior of this polygon with a color . How can I do this?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Here is one naive approach: triangulate the polygon (that's pretty easy to do and I will leave that to you to figure out) and then colour the triangles. That reduces the problem to determining the interior of a triangle that is given by three points. To do that, you could express the triangle as an intersection of three half planes. Then, each half plane is determined by a linear inequality, so given any point, you can determine whether it's in the interior by checking all three inequalities. The rest is accomplished by obvious loops, with judiciously chosen start and end values.
You can optimise some of that by putting more thought into how to set up the loops. E.g. if the outer loop goes through rows and the inner through the columns, then the starting point of the inner loop can be set to the left most point of the interior.