1

I am trying to draw curves a specified distance away from a curve. Kind of like the sides of roads are always a set distance away from the yellow lines in the center. I have code to do this, however, when done using my code it ends up with overlap in one of the curves.

Here is my code:

for (int i = 0; i < curves.Count; i++)
        {
            for (float j = 0; j < 1; j += .001f)
            {
                Vector2 temp = Vector2.CatmullRom(curves[i].Points[0], curves[i].Points[1], curves[i].Points[2], curves[i].Points[3], j);
                if (mid.Count != 0)
                {
                    if (temp != mid[mid.Count - 1])
                    {
                        mid.Add(temp);
                    }
                    else Console.WriteLine(temp == mid[mid.Count - 1]);
                }
                else mid.Add(temp);
            }
        }

for (int i = 0; i < mid.Count; i++)
        {
            if (i == 0)
            {
                Vector2 slope = mid[i] - mid[i + 1];
                double x = mid[i].X + (12 * Math.Cos(Math.Atan(-(slope.X / slope.Y)))),
                    y = mid[i].Y + (12 * Math.Sin(Math.Atan(-(slope.X / slope.Y))));
                side1.Add(new Vector2((float)x, (float)y));

                x = mid[i].X - (12 * Math.Cos(Math.Atan(-(slope.X / slope.Y))));
                y = mid[i].Y - (12 * Math.Sin(Math.Atan(-(slope.X / slope.Y))));
                side2.Add(new Vector2((float)x, (float)y));
            }
            else if (i < mid.Count - 1)
            {
                Vector2 slope1 = mid[i] - mid[i - 1],
                    slope2 = mid[i + 1] - mid[i];

                Vector2 slope = (slope1 + slope2) / 2;

                double x = mid[i].X + (12 * Math.Cos(Math.Atan(-(slope.X / slope.Y)))),
                    y = mid[i].Y + (12 * Math.Sin(Math.Atan(-(slope.X / slope.Y))));
                side1.Add(new Vector2((float)x, (float)y));

                x = mid[i].X - (12 * Math.Cos(Math.Atan(-(slope.X / slope.Y))));
                y = mid[i].Y - (12 * Math.Sin(Math.Atan(-(slope.X / slope.Y))));
                side2.Add(new Vector2((float)x, (float)y));
            }
            else
            {
                Vector2 slope = mid[i] - mid[i - 1];

                double x = mid[i].X + (12 * Math.Cos(Math.Atan(-(slope.X / slope.Y)))),
                    y = mid[i].Y + (12 * Math.Sin(Math.Atan(-(slope.X / slope.Y))));
                side1.Add(new Vector2((float)x, (float)y));

                x = mid[i].X - (12 * Math.Cos(Math.Atan(-(slope.X / slope.Y))));
                y = mid[i].Y - (12 * Math.Sin(Math.Atan(-(slope.X / slope.Y))));
                side2.Add(new Vector2((float)x, (float)y));
            }
        }

And here is a photo of the result: Curves with overlap

Any and all help would be appreciated.

  • This is what happens when offsetting curves. For overlapping curves, you will have to compute the intersection and trim the curve. For gaps between curves, you will have to fill the gaps somehow by either extending the curve tangentially or creating a fillet or bridge curve in between. – fang Dec 13 '16 at 18:22

0 Answers0