本文整理汇总了C#中Vertices.NextIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.NextIndex方法的具体用法?C# Vertices.NextIndex怎么用?C# Vertices.NextIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.NextIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollinearSimplify
/// <summary>
/// Removes all collinear points on the polygon.
/// </summary>
/// <param name="vertices">The polygon that needs simplification.</param>
/// <param name="collinearityTolerance">The collinearity tolerance.</param>
/// <returns>A simplified polygon.</returns>
public static Vertices CollinearSimplify(Vertices vertices, float collinearityTolerance)
{
//We can't simplify polygons under 3 vertices
if (vertices.Count < 3)
return vertices;
Vertices simplified = new Vertices();
for (int i = 0; i < vertices.Count; i++)
{
int prevId = vertices.PreviousIndex(i);
int nextId = vertices.NextIndex(i);
Vector2 prev = vertices[prevId];
Vector2 current = vertices[i];
Vector2 next = vertices[nextId];
//If they collinear, continue
if (MathUtils.Collinear(ref prev, ref current, ref next, collinearityTolerance))
continue;
simplified.Add(current);
}
return simplified;
}
示例2: LineSegmentVerticesIntersect
/// <summary>
/// Get all intersections between a line segment and a list of vertices
/// representing a polygon. The vertices reuse adjacent points, so for example
/// edges one and two are between the first and second vertices and between the
/// second and third vertices. The last edge is between vertex vertices.Count - 1
/// and verts0. (ie, vertices from a Geometry or AABB)
/// </summary>
/// <param name="point1">The first point of the line segment to test</param>
/// <param name="point2">The second point of the line segment to test.</param>
/// <param name="vertices">The vertices, as described above</param>
public static Vertices LineSegmentVerticesIntersect(ref Vector2 point1, ref Vector2 point2, Vertices vertices)
{
Vertices intersectionPoints = new Vertices();
for (int i = 0; i < vertices.Count; i++)
{
Vector2 point;
if (LineIntersect(vertices[i], vertices[vertices.NextIndex(i)], point1, point2, true, true, out point))
{
intersectionPoints.Add(point);
}
}
return intersectionPoints;
}
示例3: LineSegmentVerticesIntersect
/// <summary>
/// Get all intersections between a line segment and a list of vertices
/// representing a polygon. The vertices reuse adjacent points, so for example
/// edges one and two are between the first and second vertices and between the
/// second and third vertices. The last edge is between vertex vertices.Count - 1
/// and verts0. (ie, vertices from a Geometry or AABB)
/// </summary>
/// <param name="point1">The first point of the line segment to test</param>
/// <param name="point2">The second point of the line segment to test.</param>
/// <param name="vertices">The vertices, as described above</param>
/// <param name="intersectionPoints">An list of intersection points. Any intersection points
/// found will be added to this list.</param>
public static void LineSegmentVerticesIntersect(ref Vector2 point1, ref Vector2 point2, Vertices vertices,
ref List<Vector2> intersectionPoints)
{
for (int i = 0; i < vertices.Count; i++)
{
Vector2 point;
if (LineIntersect(vertices[i], vertices[vertices.NextIndex(i)],
point1, point2, true, true, out point))
{
intersectionPoints.Add(point);
}
}
}
示例4: CalculateSimplicalChain
/// <summary>
/// Calculates the simplical chain corresponding to the input polygon.
/// </summary>
/// <remarks>Used by method <c>Execute()</c>.</remarks>
private static void CalculateSimplicalChain(Vertices poly, out List<float> coeff,
out List<Edge> simplicies)
{
simplicies = new List<Edge>();
coeff = new List<float>();
for (int i = 0; i < poly.Count; ++i)
{
simplicies.Add(new Edge(poly[i], poly[poly.NextIndex(i)]));
coeff.Add(CalculateSimplexCoefficient(Vector2.Zero, poly[i], poly[poly.NextIndex(i)]));
}
}
示例5: CalculateIntersections
/// <summary>
/// Calculates all intersections between two polygons.
/// </summary>
/// <param name="polygon1">The first polygon.</param>
/// <param name="polygon2">The second polygon.</param>
/// <param name="slicedPoly1">Returns the first polygon with added intersection points.</param>
/// <param name="slicedPoly2">Returns the second polygon with added intersection points.</param>
private static void CalculateIntersections(Vertices polygon1, Vertices polygon2,
out Vertices slicedPoly1, out Vertices slicedPoly2)
{
slicedPoly1 = new Vertices(polygon1);
slicedPoly2 = new Vertices(polygon2);
// Iterate through polygon1's edges
for (int i = 0; i < polygon1.Count; i++)
{
// Get edge vertices
Vector2 a = polygon1[i];
Vector2 b = polygon1[polygon1.NextIndex(i)];
// Get intersections between this edge and polygon2
for (int j = 0; j < polygon2.Count; j++)
{
Vector2 c = polygon2[j];
Vector2 d = polygon2[polygon2.NextIndex(j)];
Vector2 intersectionPoint;
// Check if the edges intersect
if (LineTools.LineIntersect(a, b, c, d, out intersectionPoint))
{
// calculate alpha values for sorting multiple intersections points on a edge
float alpha;
// Insert intersection point into first polygon
alpha = GetAlpha(a, b, intersectionPoint);
if (alpha > 0f && alpha < 1f)
{
int index = slicedPoly1.IndexOf(a) + 1;
while (index < slicedPoly1.Count &&
GetAlpha(a, b, slicedPoly1[index]) <= alpha)
{
++index;
}
slicedPoly1.Insert(index, intersectionPoint);
}
// Insert intersection point into second polygon
alpha = GetAlpha(c, d, intersectionPoint);
if (alpha > 0f && alpha < 1f)
{
int index = slicedPoly2.IndexOf(c) + 1;
while (index < slicedPoly2.Count &&
GetAlpha(c, d, slicedPoly2[index]) <= alpha)
{
++index;
}
slicedPoly2.Insert(index, intersectionPoint);
}
}
}
}
// Check for very small edges
for (int i = 0; i < slicedPoly1.Count; ++i)
{
int iNext = slicedPoly1.NextIndex(i);
//If they are closer than the distance remove vertex
if ((slicedPoly1[iNext] - slicedPoly1[i]).LengthSquared() <= ClipperEpsilonSquared)
{
slicedPoly1.RemoveAt(i);
--i;
}
}
for (int i = 0; i < slicedPoly2.Count; ++i)
{
int iNext = slicedPoly2.NextIndex(i);
//If they are closer than the distance remove vertex
if ((slicedPoly2[iNext] - slicedPoly2[i]).LengthSquared() <= ClipperEpsilonSquared)
{
slicedPoly2.RemoveAt(i);
--i;
}
}
}
示例6: ReduceByDistance
/// <summary>
/// Reduces the polygon by distance.
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <param name="distance">The distance between points. Points closer than this will be 'joined'.</param>
/// <returns></returns>
public static Vertices ReduceByDistance(Vertices vertices, float distance)
{
//We can't simplify polygons under 3 vertices
if (vertices.Count < 3)
return vertices;
distance *= distance;
Vertices simplified = new Vertices();
for (int i = 0; i < vertices.Count; i++)
{
int nextId = vertices.NextIndex(i);
Vector2 current = vertices[i];
Vector2 next = vertices[nextId];
//If they are closer than the distance, continue
if ((next - current).LengthSquared() <= distance)
continue;
simplified.Add(current);
}
return simplified;
}
示例7: VerticesIntersect
/// <summary>
/// Check and return polygon intersections
/// </summary>
/// <param name="polygon1"></param>
/// <param name="polygon2"></param>
/// <param name="intersections"></param>
/// <returns></returns>
private static bool VerticesIntersect(Vertices polygon1, Vertices polygon2,
out List<EdgeIntersectInfo> intersections)
{
intersections = new List<EdgeIntersectInfo>();
// Iterate through polygon1's edges
for (int i = 0; i < polygon1.Count; i++)
{
// Get edge vertices
Vector2 p1 = polygon1[i];
Vector2 p2 = polygon1[polygon1.NextIndex(i)];
// Get intersections between this edge and polygon2
for (int j = 0; j < polygon2.Count; j++)
{
Vector2 point;
Vector2 p3 = polygon2[j];
Vector2 p4 = polygon2[polygon2.NextIndex(j)];
// Check if the edges intersect
if (LineTools.LineIntersect(p1, p2, p3, p4, true, true, out point))
{
// Here, we round the returned intersection point to its nearest whole number.
// This prevents floating point anomolies where 99.9999-> is returned instead of 100.
point = new Vector2((float) Math.Round(point.X, 0), (float) Math.Round(point.Y, 0));
// Record the intersection
intersections.Add(new EdgeIntersectInfo(new Edge(p1, p2), new Edge(p3, p4), point));
}
}
}
// true if any intersections were found.
return (intersections.Count > 0);
}
示例8: PreparePolygons
/// <summary>
/// Prepares the polygons.
/// </summary>
/// <param name="polygon1">The polygon1.</param>
/// <param name="polygon2">The polygon2.</param>
/// <param name="poly1">The poly1.</param>
/// <param name="poly2">The poly2.</param>
/// <param name="intersections">The intersections.</param>
/// <param name="error">The error.</param>
/// <returns></returns>
private static int PreparePolygons(Vertices polygon1, Vertices polygon2, out Vertices poly1, out Vertices poly2,
out List<EdgeIntersectInfo> intersections, out PolyUnionError error)
{
error = PolyUnionError.None;
// Make a copy of the polygons so that we dont modify the originals, and
// force vertices to integer (pixel) values.
poly1 = Round(polygon1);
poly2 = Round(polygon2);
// Find intersection points
if (!VerticesIntersect(poly1, poly2, out intersections))
{
// No intersections found - polygons do not overlap.
error = PolyUnionError.NoIntersections;
return -1;
}
// Add intersection points to original polygons, ignoring existing points.
foreach (EdgeIntersectInfo intersect in intersections)
{
if (!poly1.Contains(intersect.IntersectionPoint))
{
poly1.Insert(poly1.IndexOf(intersect.EdgeOne.EdgeStart) + 1, intersect.IntersectionPoint);
}
if (!poly2.Contains(intersect.IntersectionPoint))
{
poly2.Insert(poly2.IndexOf(intersect.EdgeTwo.EdgeStart) + 1, intersect.IntersectionPoint);
}
}
// Find starting point on the edge of polygon1
// that is outside of the intersected area
// to begin polygon trace.
int startingIndex = -1;
int currentIndex = 0;
do
{
if (!PointInPolygonAngle(poly1[currentIndex], poly2))
{
startingIndex = currentIndex;
break;
}
currentIndex = poly1.NextIndex(currentIndex);
} while (currentIndex != 0);
// If we dont find a point on polygon1 thats outside of the
// intersect area, the polygon1 must be inside of polygon2,
// in which case, polygon2 IS the union of the two.
if (startingIndex == -1)
{
error = PolyUnionError.Poly1InsidePoly2;
}
return startingIndex;
}
示例9: PointInPolygonAngle
/// <summary>
/// * ref: http://ozviz.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ - Solution 2
/// * Compute the sum of the angles made between the test point and each pair of points making up the polygon.
/// * If this sum is 2pi then the point is an interior point, if 0 then the point is an exterior point.
/// </summary>
private static bool PointInPolygonAngle(Vector2 point, Vertices polygon)
{
double angle = 0;
// Iterate through polygon's edges
for (int i = 0; i < polygon.Count; i++)
{
/*
p1.h = polygon[i].h - p.h;
p1.v = polygon[i].v - p.v;
p2.h = polygon[(i + 1) % n].h - p.h;
p2.v = polygon[(i + 1) % n].v - p.v;
*/
// Get points
Vector2 p1 = polygon[i] - point;
Vector2 p2 = polygon[polygon.NextIndex(i)] - point;
angle += VectorAngle(p1, p2);
}
if (Math.Abs(angle) < Math.PI)
{
return false;
}
return true;
}
示例10: LineSegmentVerticesIntersect
/// <summary>
/// Get all intersections between a line segment and a list of vertices
/// representing a polygon. The vertices reuse adjacent points, so for example
/// edges one and two are between the first and second vertices and between the
/// second and third vertices. The last edge is between vertex vertices.Count - 1
/// and verts0. (ie, vertices from a Geometry or AABB)
/// </summary>
/// <param name="p1">The first point of the line segment to test</param>
/// <param name="p2">The second point of the line segment to test.</param>
/// <param name="vertices">The vertices, as described above</param>
/// <param name="points">An list of intersection points. Any intersection points
/// found will be added to this list.</param>
public static void LineSegmentVerticesIntersect(ref Vector2 p1, ref Vector2 p2, Vertices vertices,
ref List<Vector2> points)
{
for (int i = 0; i < vertices.Count; i++)
{
Vector2 point;
if (LineIntersect(vertices[i], vertices[vertices.NextIndex(i)],
p1, p2, true, true, _defaultFloatTolerance, out point))
{
points.Add(point);
}
}
}