如何围绕任何线条绘制轮廓
n 个点组成的任意线(参见图 1 中所示的示例)
所以我有一条由我想要的 围绕这条线绘制轮廓(见图 2),因此我需要计算周围多边形的点。
我首先在线上进行扩张,但这不起作用 - 参见图 3
关于如何执行此操作有什么建议吗?
我怀疑计算每条线段的法线,用于平移其当前位置下方的新线和上方的新线,然后将每条新线延伸至无穷大并将点定义为交点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
首先将每条线复制两次,每边一次,距离每条原始线所需宽度的一半。这会给你图像中的绿线。然后你需要按顺序(编号)访问它们并处理未解决的问题。
当线条不相交(2-3、6-7 和 12-13)时,您添加 < em>线连接(蓝色)。线连接可以是仅连接点的斜角连接 (2-3),也可以是通过延伸线直到它们相交的斜接连接 (6-7) 或通过制作曲线进行圆形连接。
当两条线相交时,只需取交点(蓝点)即可。
在线条末端,您需要添加一个端盖(也是蓝色的)。通过连接点,端盖可以是对接盖(8-9),通过在连接线之前稍微延长线,可以是突出盖(1-16),或圆帽(未显示)。
最终结果是一个多边形(如果包含圆形连接,则为路径),然后您可以对其进行描边或填充。
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.
我找到了一种计算直线轮廓点的方法。对于原始直线的每个点,您必须计算轮廓的 2 个点:
上面的颜色对应于此图像。
我已经用 C 语言编写了这个函数,但是我使用了 Accelerate Framework,所以它不是很容易阅读。您可以在此处找到源代码以及运行演示此处。
I have figured out a way to calculate the outline points of a line. For each point of the original line you will have to compute 2 points for the outline:
The colors above correspond to this image.
I have programmed this function in C, but I used Accelerate Framework so it's not very easy to read. You can find the source code here and a video running the demo here.
在渲染之前创建所有线条。
当你这样做时,它们应该重叠,如下所示:
显然,我画的那些是那些进行修剪,露出轮廓。
Create all the lines before you render them.
When you do, they should overlap, like this:
The ones I drew, obviously, are the ones that get trimmed which would reveal the outline.
如果您有线段的点,则可以轻松地为每个线段创建两条平行线,并计算它们与下一条线相交的连接点(如果它们是线(而不是线段))。这个网站应该为您提供计算超快速交点所需的一切:
http://www.math.niu.edu/~rusin/known-math/95/line_segs
If you have the points of the line segments, you can easily create two parallel lines to each segment and calculate the connection point where they intersect with the next if they were lines (and not line segments). This site should give you all you need to calculate super fast intersections:
http://www.math.niu.edu/~rusin/known-math/95/line_segs
这是我在 Objective-C 中编写的一些代码,它正在执行此操作(即使有时有错误,我不知道为什么,让我知道它对您来说如何......):
最后,它按照所需的顺序添加每个点以形成多边形
以下是对交点的一些解释,使用 C 代码:http://alienryderflex.com/intersect/
Here is some code of mine in Objective-C that's doing it (even if it's sometimes buggy, I don't know why, let me know how it goes for you...) :
finally it adds each point in the desired order to make a polygon
Here is some explanation for the intersection point, with C code : http://alienryderflex.com/intersect/