<p>Polygon offsetting is certainly possible to do yourself. It is not nearly as involved as Bezier or B-spline offsetting is. First you want to decide how to deal with:</p>

<ol>
<li><p>Areas with no info, in essence how to deal with the joins. Do you just extend the line to the common intersection (miter join) or do you just connect the endpoints (bevel). You could also use round, parabolic or other join styles if you wish. Options here are unlimited. </p>

<p>For the purposes of this discussion I will assume you will want a miter or bevel join.</p></li>
<li><p>How do you want to deal with sidedness. Is an open curve's offset closed or just on the other side. Other than that the convention is usually in 2D that outside is on the clockwise side of the path</p></li>
</ol>

<p>So lets look at what happens when 2 straight lines join and they are offset.</p>

<p><a href="https://i.sstatic.net/jagc9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jagc9.png" alt="enter image description here"></a></p>

<p><strong>Image 1</strong>: Situation in 2D.</p>

<p>For a beveled corner join vector, from any point to its offset is magnitude of $a$. Take the direction of the segment rotated counterclockwise 90 degrees then multiply that with the length of offset. Or in the case of the picture in mathematical notation</p>

<p>$$ 
 A' = A + a\bigg(\big|B-A\big|   \begin{bmatrix}
    0 &amp; 1\\
    -1 &amp; 0 
  \end{bmatrix}\bigg)
$$</p>

<p>Where $a$ is the amount of offset. This assumes lines go from $A$ to $B$ to $C$. Connecting segments must be processed on both sides separately. The same formula can be used for all the points. Then just connect $B'^1$ to $B'^2$ with a line. In case you are matrix illiterate, the matrix says swap x and y coordinate and invert the x value.</p>

<p>For a miter join the following applies:</p>

<p><a href="https://i.sstatic.net/r6eG1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/r6eG1.png" alt="sss"></a></p>

<p><strong>Image 2</strong>: Situation of miter.</p>

<p>$$ 
 B^{B-B'^{1}} = a\bigg(\big|B-A\big| \begin{bmatrix}
    0 &amp; 1\\
    -1 &amp; 0 
  \end{bmatrix}\bigg)
$$
$$
B' = B+\dfrac{ B^{B-B'^{1}}}{B^{B-B'^{1}}  \cdot (|B-A|-|C-B|)}
$$</p>

<p>The above can be heavily simplified but I'll leave that to the reader.</p>

<p>Now the reason to use a library is that when the curves start to self intersect it gets a bit tedious to manage this. So just find a library that does this for you and you'll save a lot of time.</p>

CC BY-SA 3.0
2016-05-12T18:36:13.147Z
2016-05-14T11:16:23.827Z
2016-05-14T11:16:23.827Z
joojaa
<p>Once a 3D model is sliced against a plane and projected onto it, we get a contour curve at certain height. The contour curve I am generating in this process is made of several line segments in closed loop. Now I want to generate another contour curve with the following characteristics:</p>

<ol>
<li><p>Each of the line segment of the newly generated inner contour curve must be parallel to the corresponding line segments at the outer contour curve.</p></li>
<li><p>Each of the parallel line segments on both outer and inner contour curve has an adjacent distance in between and defined by a constant value as shown in the attached picture (green mark) </p></li>
</ol>

<p><a href="https://i.sstatic.net/cptpE.jpg" rel="nofollow noreferrer">Image Link</a> </p>

<p>I need some suggested algorithms to generate it . I hope that I have explained the issue properly. Please do let me know if it is not clear enough.</p>

<p>Thanks</p>

CC BY-SA 3.0
2016-05-10T02:16:25.833Z
The magic keyword to search for is "polygon offsetting". The curves you're trying to generate are called offset curves. [Here is a StackOverflow question](http://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons) with some good background and links to some libraries that can do it. You can also find plenty of material with a web search.
Nathan Reed
<computational-geometry>
generate multiple border contour
sajis997
# generate multiple border contour

(Asked by: username_0 on 2016-05-09)

Once a 3D model is sliced against a plane and projected onto it, we get a contour curve at certain height. The contour curve I am generating in this process is made of several line segments in closed loop. Now I want to generate another contour curve with the following characteristics:

1. Each of the line segment of the newly generated inner contour curve must be parallel to the corresponding line segments at the outer contour curve.
2. Each of the parallel line segments on both outer and inner contour curve has an adjacent distance in between and defined by a constant value as shown in the attached picture (green mark)

[Image Link](https://i.sstatic.net/cptpE.jpg)

I need some suggested algorithms to generate it . I hope that I have explained the issue properly. Please do let me know if it is not clear enough.

Thanks

**Tags:** computational-geometry

> **Comments:**
> **username_1**: The magic keyword to search for is "polygon offsetting". The curves you're trying to generate are called offset curves. [Here is a StackOverflow question](http://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons) with some good background and links to some libraries that can do it. You can also find plenty of material with a web search.  

---

## 1 answers

### Answer by username_2 on 2016-05-12. Score: 4

Polygon offsetting is certainly possible to do yourself. It is not nearly as involved as Bezier or B-spline offsetting is. First you want to decide how to deal with:

1. Areas with no info, in essence how to deal with the joins. Do you just extend the line to the common intersection (miter join) or do you just connect the endpoints (bevel). You could also use round, parabolic or other join styles if you wish. Options here are unlimited.

   For the purposes of this discussion I will assume you will want a miter or bevel join.
2. How do you want to deal with sidedness. Is an open curve's offset closed or just on the other side. Other than that the convention is usually in 2D that outside is on the clockwise side of the path

So lets look at what happens when 2 straight lines join and they are offset.

[![enter image description here](https://i.sstatic.net/jagc9.png)](https://i.sstatic.net/jagc9.png)

**Image 1**: Situation in 2D.

For a beveled corner join vector, from any point to its offset is magnitude of $a$. Take the direction of the segment rotated counterclockwise 90 degrees then multiply that with the length of offset. Or in the case of the picture in mathematical notation

$$
A' = A + a\bigg(\big|B-A\big| \begin{bmatrix}
0 & 1\\
-1 & 0
\end{bmatrix}\bigg)
$$

Where $a$ is the amount of offset. This assumes lines go from $A$ to $B$ to $C$. Connecting segments must be processed on both sides separately. The same formula can be used for all the points. Then just connect $B'^1$ to $B'^2$ with a line. In case you are matrix illiterate, the matrix says swap x and y coordinate and invert the x value.

For a miter join the following applies:

[![sss](https://i.sstatic.net/r6eG1.png)](https://i.sstatic.net/r6eG1.png)

**Image 2**: Situation of miter.

$$
B^{B-B'^{1}} = a\bigg(\big|B-A\big| \begin{bmatrix}
0 & 1\\
-1 & 0
\end{bmatrix}\bigg)
$$
$$
B' = B+\dfrac{ B^{B-B'^{1}}}{B^{B-B'^{1}} \cdot (|B-A|-|C-B|)}
$$

The above can be heavily simplified but I'll leave that to the reader.

Now the reason to use a library is that when the curves start to self intersect it gets a bit tedious to manage this. So just find a library that does this for you and you'll save a lot of time.


---

