Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? enter image description here

like image 552
N.T.C Avatar asked May 12 '26 03:05

N.T.C


1 Answers

enter image description here

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))/2)

(derived from l=d/cos(fi/2) and half-angle cosine formula)

And get offset polygon vertex (use minus for inner offset!):

P' = P + l * bis

Added: python implementation here

like image 177
MBo Avatar answered May 13 '26 20:05

MBo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!