Search code examples
algorithmpolygonoffsetpoint

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


Solution

  • 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)

    enter image description here