How to draw an outline around any line

后端 未结 5 1792
一生所求
一生所求 2020-12-09 06:11

\"enter

So I have a arbitary line (See an example shown in fig 1) made up of n points<

5条回答
  •  情歌与酒
    2020-12-09 06:40

    I have figured out a way to calculate the outline points of a line. For each point of the original line you will have to compute 2 points for the outline:

    1. for each line segment of the original line (between 2 points) you have to compute its normal vector (red)
    2. for each point, add the normals of the previous and next line segment. This produces a new vector (green)
    3. divide the new vector with the value: kl+1 , where kl is the dot product of the normal vectors. You'll get the blue vector. Then add this vector on the current point and its opposite vector and you'll get the 2 outline points for the current point

    The colors above correspond to this image.

    I have programmed this function in C, but I used Accelerate Framework so it's not very easy to read. You can find the source code here and a video running the demo here.

提交回复
热议问题