本文整理汇总了C#中Polyline.GetOffsetCurves方法的典型用法代码示例。如果您正苦于以下问题:C# Polyline.GetOffsetCurves方法的具体用法?C# Polyline.GetOffsetCurves怎么用?C# Polyline.GetOffsetCurves使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polyline
的用法示例。
在下文中一共展示了Polyline.GetOffsetCurves方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOffsetPolyline
public static Polyline GetOffsetPolyline(Polyline line, bool IsLeftComp, double r)
{
Polyline newLine = new Polyline();
double offsetValue = (IsLeftComp) ? -r : r;
for (int i = 1; i <= line.NumberOfVertices - 1; i++)
{
Polyline pl1 = new Polyline();
pl1.AddVertexAt(0, line.GetPoint2dAt(i - 1), line.GetBulgeAt(i - 1), 0, 0);
pl1.AddVertexAt(1, line.GetPoint2dAt(i), line.GetBulgeAt(i), 0, 0);
Polyline pl1Offset = pl1.GetOffsetCurves(offsetValue)[0] as Polyline;
AddToDrawing(pl1Offset);//debug
if (i == 1)//第一点,且当前曲线并不是封闭的
{
newLine.AddVertexAt(0, new Point2d(pl1Offset.StartPoint.X, pl1Offset.StartPoint.Y), 0, 0, 0);
if (line.NumberOfVertices == 2)//如果只是一条线的话
{
newLine.AddVertexAt(0, new Point2d(pl1Offset.EndPoint.X, pl1Offset.EndPoint.Y), -pl1Offset.GetBulgeAt(0), 0, 0);
}
}
if (line.NumberOfVertices > 2 && i < line.NumberOfVertices - 1)
{
Polyline pl2 = new Polyline();
pl2.AddVertexAt(0, line.GetPoint2dAt(i), line.GetBulgeAt(i), 0, 0);
pl2.AddVertexAt(1, line.GetPoint2dAt(i + 1), line.GetBulgeAt(i + 1), 0, 0);
Polyline pl2Offset = pl2.GetOffsetCurves(offsetValue)[0] as Polyline;
AddToDrawing(pl2Offset);//debug
//两个偏移后的Polyline进行相交
Point3dCollection points = new Point3dCollection();
pl2Offset.IntersectWith(pl1Offset, Intersect.ExtendBoth, points, IntPtr.Zero, IntPtr.Zero);
Point2d TheIntersectPoint;
if (points.Count == 0)
{
//无交点,只存在于两个在同一根直线上的情况
//或者同一个圆上
newLine.AddVertexAt(0, pl1Offset.GetPoint2dAt(1), -pl1Offset.GetBulgeAt(1), 0, 0);
continue;
}
else if (points.Count == 1)
TheIntersectPoint = new Point2d(points[0].X, points[0].Y);//1个交点,说明是直线和直线相交
else
{
//2个交点,那就需要判断是哪一个了
//与pl2offset的终点进行比较,距离较近的那个就是了
double dist1 = points[0].DistanceTo(pl2.StartPoint);
double dist2 = points[1].DistanceTo(pl2.StartPoint);
if (dist1 > dist2)
TheIntersectPoint = new Point2d(points[1].X, points[1].Y);
else
TheIntersectPoint = new Point2d(points[0].X, points[0].Y);
}
double newBulge = GetOffsetCurveBulge.Get(IsLeftComp, r, line, TheIntersectPoint, i, pl1Offset.GetPoint2dAt(0));
newLine.AddVertexAt(0, TheIntersectPoint, newBulge, 0, 0);
if (i == line.NumberOfVertices - 2)//最后一个点的时候
{
double bulge = GetOffsetCurveBulge.Get(IsLeftComp, r, line, pl2Offset.GetPoint2dAt(1), i + 1, pl2Offset.GetPoint2dAt(0));
newLine.AddVertexAt(0, new Point2d(pl2Offset.EndPoint.X, pl2Offset.EndPoint.Y), bulge, 0, 0);
}
pl2.Dispose();
pl2Offset.Dispose();
}
pl1.Dispose();
pl1Offset.Dispose();
}
ReversePolyline(newLine);
// newLine.ReverseCurve();//反转多段线
return newLine;
}