我正在尝试从曲线绘制指定距离的曲线。有点像道路的两侧总是距离中心的黄线有一定距离。我有代码来执行此操作,但是,当使用我的代码完成时,它最终会在其中一条曲线中重叠。
这是我的代码:
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));
}
}
这是结果的照片: Curves with overlap
任何和所有帮助将不胜感激。