简体   繁体   English

如何偏移多边形边缘?

[英]How to offset polygon edges?

I have a list of point2D that makes a closed polygon.我有一个生成闭合多边形的 point2D 列表。 Now I want to create another set of 2D points by offsetting the polygon given an option inside or outside and an offset value.现在我想通过在给定内部或外部选项和偏移值的情况下偏移多边形来创建另一组 2D 点。 How can I do it?我该怎么做? 在此处输入图片说明

在此处输入图片说明

For every polygon vertex calculate outer bisector vector as sum of normalized normals na and nb of two neighbor edges), then normalize it对于每个多边形顶点,计算外部平分向量作为两个相邻边的归一化法线nanb的总和),然后对其进行归一化

 bis = na + nb 
 bis = bis / Length(bis)

Then find needed length of bisector to provide offset distance as然后找到所需的平分线长度以提供偏移距离为

 l = d / Sqrt(1 + dotproduct(na,nb))

And get offset polygon vertex (use minus for inner offset!):并获得偏移多边形顶点(使用减号作为内部偏移!):

P' = P + l * bis

Added: python implementation here补充:这里的python实现

You need to work with dircetion to be able to define what is outside/inside.您需要使用 dircetion 才能定义外部/内部。 Better is to work with to the left/right of the arrow (vector).更好的是使用箭头(向量)的左侧/右侧。

In my example the offset is to the right of the vector, now you need to calculate all intersections of the red lines to define the new start-end points of the lines.在我的示例中,偏移量位于向量的右侧,现在您需要计算红线的所有交点以定义线的新起点-终点。

Example: P0 = (5,2) & P1 = (2, 1.7)示例:P0 = (5,2) & P1 = (2, 1.7)

V1 = -3, -0.3. V1 = -3,-0.3。 Rotating clock wise 90deg gives us vector -0.3, 3 (a,b) -> (b, -a)顺时针旋转 90 度给我们向量 -0.3, 3 (a,b) -> (b, -a)

Divide the vector by 3 (thats about the distance in the drawing) gives us (-0.1, 1) ofsetting point P0 by the vector gives P0' (5,2) - v(-0.1,1) = (4.9, 3)将向量除以 3(大约是图中的距离)给我们 (-0.1, 1) 设置点 P0 除以向量给出 P0' (5,2) - v(-0.1,1) = (4.9, 3)

在此处输入图片说明

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

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