I have a set of points representing a line. It might be a closed shape or an open one. I need to draw a parallel line that goes besides the original one without any intersection.
I have the following code to return the generated line. I have problems in the angles of the shape. Some point goes over the original line.
My Code is:
PointF[] GetParrarel(PointF[] lst, double width, float distance)
{
List<PointF> final = new List<PointF>();
width = width + distance;
for (int i = 0; i < lst.Length-1 ; i++)
{
int index = i;
PointF current = lst[index];
PointF next = lst[index + 1];
double dx = next.X - current.X;
double dy = next.Y - current.Y;
PointF first = current;
PointF second = next;
if (dx > 0)
{
if (dy == 0)
{
first.Y += (float)width;
second.Y += (float)width;
}
first.X += (float)width;
second.X += (float)width;
}
else if (dx < 0)
{
if (dy == 0)
{
first.Y -= (float)width;
second.Y -= (float)width;
}
first.X -= (float)width;
second.X -= (float)width;
}
else //// X = 0
{
if (dy > 0)
{
first.X -= (float)width;
second.X -= (float)width;
}
else if (dy < 0)
{
first.X += (float)width;
second.X += (float)width;
}
else
{
continue;
}
}
final.Add(first);
final.Add(second);
}
return final.ToArray();
}
See Question&Answers more detail:os