Polygon Clipping is a complex operation that requires an outer polygon and an inner polygon. The outer polygon will usually be a rectangle which simplifies operations a bit. One of the most common implementations of Polygon Clipping is the Liang – Barsky algorithm and here you can find one implementation in Java. After clipping, a filling algorithm can be used to fill the polygon. The most common algorithm is the flood filling algorithm and here (method floodFill(int row, int col, Color oldColor, Color newColor)) is an implementation in Java. Note that in order to fill an arbitrary polygon you will have to improve the method by testing if a given lies within the polygon.
No comments:
Post a Comment