多边形三角测量的相反之处是什么? [英] What's the opposite of polygon triangulation?

查看:412
本文介绍了多边形三角测量的相反之处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成二维三角测量后,一些三角形具有相同的颜色,我想重新组合它们以绘制类似的图形路径。我发现如果我只是逐一绘制三角形,一些图形渲染器会显示三角形之间的接缝(至少如果涉及到抗锯齿和/或透明度)。

那么如何获取一组(不重叠的)三角形并生成可能包含空洞和不相交多边形的图形路径?



将三角形盲区添加到图形路径实际上对于填充效果非常好(虽然不是用于抚摸,当然),但是导出这些额外的内部点不适合。 class =h2_lin>解决方案



  

< - ^
| /
| /
V

因此,对于形状中的所有三角形,取其轮廓矢量的联合。如果联合中的两个轮廓矢量是相同的,但方向相反,它们会互相抵消并从联合中删除。

例如,对于两个三角形工会是6个向量


 <  -  ^^ 
| // |
| // |
VV - >

它减少到4个向量,因为中间的两个对角向量因为相同而被取消相反的方向:

 <  -  ^ 
| |
| |
V - >

您会发现这适用于较大的三角形聚合。只需连接结果矢量尾部即可获得封闭路径。一些封闭的路径可能会顺时针运行,这些都是漏洞。

 < -----< --- - < ----- ^ 
| |
| |
V ^ -----> ^
| | | |
| | | |
V <----- V ^
| |
| |
V -----> -----> ----->


After I've done a 2D triangulation, some triangles have the same color and I want to recombine them for drawing into like-colored graphics paths. I find that if I just draw the triangles one by one, some graphic renderers shows seams between the triangles (at least if anti-aliasing and/or transparency is involved).

So how do I take a set of (non-overlapping) triangles and produce a graphics path, which may contain holes and disjoint polygons?

Blindly adding the triangles to a graphics path actually works pretty well for filling (though not for stroking, of course), but it doesn't feel right to export those extra interior points.

解决方案

Think of each triangle as an outline comprised of three vectors going in a counter-clockwise chain.

<--^
| /
|/ 
V

So for all the triangles in your shape, take the union of their outline vectors. If two outline vectors in the union are identical but go in opposite directions, they cancel each other out and are removed from the union.

For example, for two triangles that are side by side the union is 6 vectors

<--^^
| //|
|// |
VV-->

which reduces to 4 vectors because the two diagonal vectors in the middle cancel because they are identical but run in opposite directions:

<--^
|  |
|  |
V-->

You'll find this works for larger aggregations of triangles. Just connect the resulting vectors tail to head to get closed paths. Some of the closed paths may run clockwise, and these are holes.

<-----<-----<-----^
|                 |
|                 |
V     ^----->     ^
|     |     |     |
|     |     |     |
V     <-----V     ^
|                 |
|                 |
V----->----->----->

这篇关于多边形三角测量的相反之处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆