问题描述
所以我有一条由 n 个点组成的任意线(参见图 1 中的示例)
So I have a arbitary line (See an example shown in fig 1) made up of n points
我想围绕这条线画一个轮廓(见图 2),所以我需要计算周围多边形的点.
I want to draw an outline around this line (see fig 2) so I need to calculate the points of the surrounding polygon.
我首先在线上执行扩张,但这行不通 - 见图 3
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.
当线不相交时(2-3、6-7 和 12-13),您添加一个线连接(蓝色).线连接可以是 斜连接 (2-3) 通过连接点,或 斜接 通过延长线直到它们相遇 (6-7) 或圆形连接通过制作曲线.
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).
在行尾,您需要添加一个端盖(同样为蓝色).通过连接点,端盖可以是 butt cap (8-9),通过在连接它们之前稍微延长线,可以是 projecting cap (1-16),或圆帽(未显示).
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.
这篇关于如何在任何线周围绘制轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!