• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

针对矩形裁剪多边形

用户头像
it1352
帮助1

问题说明

今天,我有一个(简单的)渲染问题.我当前的项目从文件获取数据以生成SVG文件.多亏了SVG格式,将事物绘制为多边形非常容易,但是我有一个问题:我的某些多边形位于页面的AND内(这意味着它们中的某些部分会显示,而其余部分由于事实而不会显示)它们超出了显示限制).为了优化最终的SVG文件,我需要将多边形缩小为更简单的形式.

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 :)

我也要处理这个棘手的情况:

I have this tricky case to handle as well :

谢谢.

正确答案

#1
  1. 使用矩形剪切多边形.我们将这个问题减少到
  2. 使用线剪切多边形.我们将其简化为一个更简单的问题:
  3. 用一条线剪切多边形的一个边缘.真的是
  4. 查找线段与线的交点(如果存在).
  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?

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangjaiae
系列文章
更多 icon
同类精品
更多 icon
继续加载