简体   繁体   中英

How to offset polygon edges?

I have a list of point2D that makes a closed polygon. Now I want to create another set of 2D points by offsetting the polygon given an option inside or outside and an offset value. 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

 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

You need to work with dircetion to be able to define what is outside/inside. 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)

V1 = -3, -0.3. Rotating clock wise 90deg gives us vector -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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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