clipping polygon against rectangle

梦想的初衷 提交于 2019-12-23 17:27:46

问题


today I have a (simple) rendering problem for you. My current project gets datas from a file to generate a SVG file. Drawing things as polygon is pretty easy thanks to the SVG format, but I have a single problem: some of my polygons are in AND out of the page (meaning that some parts of them are displayed while the rest is not shown due to the fact they are out of the display limit). In order to optimize the final SVG file I need to reduce my polygon to a simpler form.

Consider the grey rectangle as my page. Consider the green polygon as the thing I actually draw.

First picture shows you the thing that I actually have while the second picture shows you the final result I want to have.

First I thought to reduce my polygon in simple triangles in order to only draw points in the display limits. But I think a simpler solution exists... if you have it do not hesitate to share it with me :)

EDIT:

I have this tricky case to handle as well :

Thank you.


回答1:


  1. Clipping a polygon with a rectangle. We reduce this problem to
  2. clipping a polygon with a line. We reduce this to an even simpler problem:
  3. clipping one edge of a polygon with a line. Which is really just
  4. Finding the intersection of a line segment with a line (if it exists).

The last problem is pretty easy, considering that your lines are vertical or horizontal. Is that enough?



来源:https://stackoverflow.com/questions/6243411/clipping-polygon-against-rectangle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!