本文整理汇总了C#中System.Line.GetDistance方法的典型用法代码示例。如果您正苦于以下问题:C# Line.GetDistance方法的具体用法?C# Line.GetDistance怎么用?C# Line.GetDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Line
的用法示例。
在下文中一共展示了Line.GetDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIntersection
public static Vector2D[] GetIntersection(Vector2D[] vertexes, Line line)
{
Scalar[] distances = new Scalar[vertexes.Length];
for (int index = 0; index < vertexes.Length; ++index)
{
line.GetDistance(ref vertexes[index], out distances[index]);
}
Scalar lastDistance = distances[distances.Length - 1];
Vector2D lastVertex = vertexes[vertexes.Length - 1];
Vector2D vertex;
Scalar distance;
List<Vector2D> result = new List<Vector2D>(vertexes.Length + 1);
for (int index = 0; index < vertexes.Length; ++index, lastVertex = vertex, lastDistance = distance)
{
vertex = vertexes[index];
distance = distances[index];
if (Math.Abs(Math.Sign(distance) - Math.Sign(lastDistance)) == 2)
{
Scalar lastABS = Math.Abs(lastDistance);
Scalar total = (lastABS + Math.Abs(distance));
Scalar percent = lastABS / total;
Vector2D intersection;
Vector2D.Lerp(ref lastVertex, ref vertex, ref percent, out intersection);
result.Add(intersection);
}
if (distance >= 0)
{
result.Add(vertex);
}
}
return result.ToArray();
}