本文整理汇总了C#中Polyline.GetBulgeAt方法的典型用法代码示例。如果您正苦于以下问题:C# Polyline.GetBulgeAt方法的具体用法?C# Polyline.GetBulgeAt怎么用?C# Polyline.GetBulgeAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polyline
的用法示例。
在下文中一共展示了Polyline.GetBulgeAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public static double Get(bool IsLeftComp, double r, Polyline line, Point2d TheIntersectPoint, int Index, Point2d StartPoint)
{
double oldBulge = line.GetBulgeAt(Index - 1);
if (oldBulge == 0)
return 0;//这里可能不对,可能有两个交点,而默认为一个交点
else
{
double delta = System.Math.Atan(System.Math.Abs(oldBulge)) * 2;
//这里计算新的半径时,要考虑方向因素,可能新半径会更小,也可能会更大
//取决于路径的偏移方向,以及圆心的位置
double newRadius = line.GetPoint2dAt(Index - 1).GetDistanceTo(line.GetPoint2dAt(Index)) / 2 / System.Math.Sin(delta);//新弧的半径
if (IsLeftComp)
{
if (oldBulge < 0)
newRadius += r;
else newRadius -= r;
}
else
{
if (oldBulge > 0)
newRadius += r;
else newRadius -= r;
}
double newChord = StartPoint.GetDistanceTo(TheIntersectPoint);
double newBulge = System.Math.Tan(
System.Math.Asin(newChord / 2 / newRadius) / 2
)
* line.GetBulgeAt(Index - 1) / System.Math.Abs(line.GetBulgeAt(Index - 1));
return -newBulge;
}
}
示例2: 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;
}
示例3: ReversePolyline
public static void ReversePolyline(Polyline pl)
{
if (pl != null)
{
// Collect our per-vertex data
List<PerVertexData> vertData =
new List<PerVertexData>(pl.NumberOfVertices);
for (int i = 0; i < pl.NumberOfVertices; i++)
{
PerVertexData pvd = new PerVertexData();
pvd.bulge = (i > 0 ? pl.GetBulgeAt(i - 1) : 0);
pvd.startWidth = (i > 0 ? pl.GetStartWidthAt(i - 1) : 0);
pvd.endWidth = (i > 0 ? pl.GetEndWidthAt(i - 1) : 0);
pvd.pt = pl.GetPoint2dAt(i);
vertData.Add(pvd);
}
// Write the data back to the polyline, but in
// reverse order
for (int i = 0; i < pl.NumberOfVertices; i++)
{
PerVertexData pvd =
vertData[pl.NumberOfVertices - (i + 1)];
pl.SetPointAt(i, pvd.pt);
pl.SetBulgeAt(i, -pvd.bulge);
pl.SetStartWidthAt(i, pvd.endWidth);
pl.SetEndWidthAt(i, pvd.startWidth);
}
}
}