5

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

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

Nero
  • 1,320
  • 3
  • 15
  • 31
sajis997
  • 1,279
  • 1
  • 10
  • 15
  • 3
    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 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 May 10 '16 at 02:16

1 Answers1

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

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

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.

joojaa
  • 8,437
  • 1
  • 24
  • 47