如何绘制任何线条的轮廓 [英] How to draw an outline around any line

查看:283
本文介绍了如何绘制任何线条的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有一个由n点组成的任意线(参见图1所示的示例)我想画一条围绕这条线的轮廓(见图2),所以我需要以计算周围多边形的点。



我开始在线上进行扩张,但这不会奏效 - 见图3

有关如何做到这一点的任何建议?



我怀疑计算每条线段的法线,以便用于翻译下面的新线条和在当前位置上方的新线条,然后将每条新线条延伸到无穷大并定义点作为交叉点?

解决方案

首先复制每一行两次,每一次在距离您想要的一半宽度来自每条原始线路。这给了你图像中的绿线。然后你需要按顺序访问它们(编号)并处理松散的结尾。





当线条不符合(2-3,6-7和12-13)时,您添加线条连接(蓝色)。线连接可以通过连接点来实现斜角连接(2-3),或者通过延长线直到它们相遇(6-7)或连接



当线条相交时,只需取交点(蓝点)即可。



在行结束时,您需要添加一个 end cap (也是蓝色)。通过在连接点之前将端点连接起来,可以通过连接点将突出端帽(1-16)连接到一个端帽(<8-9>)(1-16)或者一个圆形的帽子(未示出)。

最终的结果是一个多边形(或者包含圆形连接的路径),然后你可以中风或填充。

So I have a arbitary line (See an example shown in fig 1) made up of n points

I want to draw an outline around this line (see fig 2) so I need to calculate the points of the surrounding polygon.

I started by performing a dilation on the line but this wont work - see figure 3

Any suggestions on how to do this?

I suspect calculating the normal of each line segment for use in translating the new line below and a new line above its current position and then extending each new line to infinity and defining the points as the intersections?

解决方案

First duplicate each line twice, once on each side at a distance of half the width you want from each original line. That gives you the green lines in the image. Then you need to visit them in order (numbered) and deal with the loose ends.

When the lines don't meet (2-3, 6-7 and 12-13) you add a line join (in blue). A line join can be a bevel join (2-3) by just connecting the points, or a miter join by extending the lines until they meet (6-7) or a round join by making a curve.

When the lines do meet, just take the intersection point (blue dots).

At the line ends, you need to add an end cap (also in blue). An end cap can be a butt cap (8-9) by connecting the points, a projecting cap (1-16) by extending the lines a little before connecting them, or a round cap (not shown).

The end result is a polygon (or path if it includes round joins) that you can then stroke or fill.

这篇关于如何绘制任何线条的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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