有一系列的多边形坐标,现在需要用一个矩形的区域来将他们裁剪,超过矩形区域的点删除或与矩形边界求交,请问有没有什么高速的方法? 分别与各边进行切割的算法如果可以达到惊人的速度也可.

解决方案 »

  1.   


                              \
    A(x0,y0) ------------ D    \
             |          |       \
             |          |        \
             |          |         \
             |          |          \
            B------------ C(x1,y1)  \
                                     \Line1
    1. Trivial reject
       a. if both ends are higher than y0, reject
       b. if both ends are lower than y1, reject
       c. if both ends are larger than x1, reject
       d. if both ends are smaller than x0, reject2. 'Trivial reject' is fast and should clip many of the polygon sides.
       if you are not satisfied and want to cut more, you might look into 
       algorithm like Cohen-Sutherland Line-Clipping. here is a link:Computer Graphics - Clipping
      

  2.   

    thank gomoku,your method cut a side one by one only,
    but I am interesting in your link~thanks a lot!