简体   繁体   English

是否有算法生成图形轮廓?

[英]Is there an algorithm to generate a graph outline?

I've searched the Internet and maybe I'm missing some correct keywords but I managed to find nothing like this. 我搜索过互联网,也许我错过了一些正确的关键字,但我设法找不到这样的东西。 I only found the poly-lines (or just the lines) which are not exactly the graphs. 我只找到了不完全是图形的多边形线(或只是线条)。 I would like to generate a graph outline (of radius r ) as seen in the picture. 我想生成一个图形轮廓(半径为r ),如图所示。 Is there something already available? 有没有可用的东西? I would like to avoid reinventing the wheel so to speak. 我想避免重新发明轮子这么说。

在此输入图像描述

If anyone can at hint me at something or at least at some basic principle how to do it it would be great. 如果有人能够暗示某些东西或者至少在一些基本原则上如何做到这一点那就太棒了。 Otherwise I'll "invent" one on my own of course. 否则我当然会自己“发明”一个。

Optimally in C#. 在C#中最佳。

Update: I need to calculate outline polygon, not just visually draw it. 更新:我需要计算轮廓多边形,而不是直观地绘制它。 The green points represents the resulting polygon. 绿色点表示生成的多边形。 Also the "inner" holes are ignored completely. “内部”洞也完全被忽略了。 Only one outline polygon should be enough. 只有一个轮廓多边形就足够了。

Update 2 : Better picture to show some more extreme cases. 更新2 :更好的图片,以显示一些更极端的情况。 Also the edges of graph never overlap so no need to accommodate for that. 图形的边缘也不会重叠,因此无需适应。

Update 3 : Picture updated yet again to reflect the bevel joins. 更新3 :图片再次更新以反映斜角连接。

First, for every "line piece" from point A to B, generate the rectangle to it (all 4 points as "path", so to say). 首先,对于从A点到B点的每个“线条”,为它生成矩形(所有4个点都作为“路径”,所以说)。 Then search two overlapping rectangles and merge them: 然后搜索两个重叠的矩形并合并它们:

Merging is a bit complicated, the idea: Start with calculating the angle of all 8 lines (eg. if the rectangles are traversed clockwise). 合并有点复杂,这个想法:从计算所有8条线的角度开始(例如,如果矩形顺时针移动)。 Then traverse one rectangle until the first line-line-intersection, check with the angles which direction is "outside", and move along the crossing line of the second rectangle ... until you arrive at the start point again => Now you traversed the shape of both together (and hopefully saved it somewhere). 然后遍历一个矩形直到第一个线 - 线交叉点,检查方向是“外”的角度,并沿第二个矩形的交叉线移动......直到再次到达起点=>现在你遍历两者的形状(并希望在某处保存)。

Merge until only one large piece is left (or multiple non-overlapping pieces). 合并直到只留下一个大块(或多个不重叠的块)。 In theory, starting from any point, you can traverse the whole shape, but there´s another problem: Holes are possible. 从理论上讲,从任何一点开始,你都可以遍历整个形状,但还有另一个问题:孔是可能的。
If one shape has two or more disjuct sets of points (where no point from set 2 is reachable from set 1 and vice-versa), all but one disjunct path is of a hole. 如果一个形状具有两个或更多个脱离点组(其中组2中没有点可从组1到达,反之亦然),则除了一个分离路径之外的所有点都是孔。 An easy possibility to get the real outer border is to search for an extremum, ie. 获得真正外边界的简单方法是搜索极值,即。 the point with the largest or smallest X or Y coordinate (only one of the 4 combinations in enough). 具有最大或最小X或Y坐标的点(仅4种组合中的一种足够)。 This point surely is a part of the outer border. 这一点肯定是外边界的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM