There is a broken line (given by an array of points) and you need to find a broken line envelope of the original one, which is probably more understandable in the figure (blue is the one you need to build):

enter image description here

Ie, if you build a broken line on new points, it should repeat and bend around the initial one. What formulas can be calculated if a two-dimensional array with dots is specified?

  • You have drawn a "naive" example. And in real life, a new broken line can intersect itself. What to do then? - AnT
  • And what was the problem? With the construction of a straight line parallel to the line segment and located at a given distance from it? Finding the intersection point of two such lines? And note that the distance from such an intersection point to a common vertex of two segments will be greater than a specified distance ... it should be rounded off. - Akina

1 answer 1

For each node P find the vectors of neighboring edges and determine unit normals na, nb to them, directed in the same direction with respect to the polyline (let it be called external).

enter image description here

Build the external vector of the bisector as the sum of normals, normalize it

  bis = na + nb bis = bis / Length(bis) 

To provide the necessary distance d to new segments, the length of the bisector l must be

  l = d / Cos(fi/2) 

where fi is the angle between the normals

  fi = atan2(crossproduct(na,nb), dotproduct(na,nb)) 

Option without trigonometry:

 Cos(fi/2) = Sqrt(1+dotproduct(na,nb)) или l = d / Sqrt(1+dotproduct(na,nb)) 

And finally, the new polyline node:

  P' = P + l * bis 

In the general case, loops and the like may appear on the "broken polyline" even in the absence of self-intersections of the base polyline. effects.