本文整理汇总了C#中Polygon.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.Contains方法的具体用法?C# Polygon.Contains怎么用?C# Polygon.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.Contains方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddInnerFill
public void AddInnerFill(Transform root, Vector3[] points, float pathLength)
{
Polygon poly = new Polygon(points);
Bounds b = points.GetBounds();
float s = size * 2 * spacing;
int index = 0;
for (float x = b.min.x; x < b.max.x; x += s) {
for (float y = b.min.y; y < b.max.y; y += s) {
Vector3 p = new Vector3(x, y, 0);
if (poly.Contains(p)) {
AddObject(root, p, Vector3.right, ref index, 0);
}
}
}
root.DestroyChildrenAfter(index);
}
示例2: AddScatterFill
public void AddScatterFill(Vector3[] points, float pathLength)
{
Polygon poly = new Polygon(points);
Bounds b = points.GetBounds();
float s = size * 2 * spacing;
if (allowOverflow) {
poly = poly.GetOffset(2 * s);
b.Expand(s);
}
int index = 0;
for (float x = b.min.x; x < b.max.x; x += s) {
for (float y = b.min.y; y < b.max.y; y += s) {
Vector3 p = new Vector3(x, y, 0);
if (poly.Contains(p)) {
AddScatterQuad (p, Vector3.right, ref index, 0);
}
}
}
}
示例3: UpdateIntersectionPolygon
private void UpdateIntersectionPolygon(ArbiterIntersection aInt)
{
// get previous polygon
Polygon interPoly = new Polygon();
// add all turn points
foreach (ArbiterInterconnect ai in aInt.PriorityLanes.Keys)
{
interPoly.AddRange(ai.TurnPolygon);
}
// wrap it to get intersection polygon
interPoly = Polygon.GrahamScan(interPoly);
// get outer edges of poly
List<LinePath> polyEdges = new List<LinePath>();
for (int i = 0; i < interPoly.Count; i++)
{
Coordinates init = interPoly[i];
Coordinates fin = i == interPoly.Count - 1 ? interPoly[0] : interPoly[i + 1];
polyEdges.Add(new LinePath(new Coordinates[] { init, fin }));
}
// get all edges of all the turns
List<LinePath> other = new List<LinePath>();
foreach (ArbiterInterconnect ai in aInt.PriorityLanes.Keys)
{
for (int i = 0; i < ai.TurnPolygon.Count; i++)
{
Coordinates init = ai.TurnPolygon[i];
Coordinates fin = i == ai.TurnPolygon.Count - 1 ? ai.TurnPolygon[0] : ai.TurnPolygon[i + 1];
other.Add(new LinePath(new Coordinates[] { init, fin }));
}
}
// test points
List<Coordinates> testPoints = new List<Coordinates>();
// path segs of inner turns
List<LinePath> innerTurnPaths = new List<LinePath>();
// check all inner points against all turn edges
foreach (ArbiterInterconnect ai in aInt.PriorityLanes.Keys)
{
// check for inner point
if (ai.InnerCoordinates.Count == 3)
{
// inner point of the turn on the inside
testPoints.Add(ai.InnerCoordinates[1]);
// add to paths
innerTurnPaths.Add(new LinePath(new Coordinates[] { ai.InnerCoordinates[0], ai.InnerCoordinates[1] }));
innerTurnPaths.Add(new LinePath(new Coordinates[] { ai.InnerCoordinates[1], ai.InnerCoordinates[2] }));
}
}
// list of used segments
List<LinePath> closed = new List<LinePath>();
// check all other intersections of turn polygon edges
foreach (LinePath seg in innerTurnPaths)
{
foreach (LinePath otherEdge in other)
{
if (!seg.Equals(otherEdge) && !closed.Contains(otherEdge))
{
double x1 = seg[0].X;
double y1 = seg[0].Y;
double x2 = seg[1].X;
double y2 = seg[1].Y;
double x3 = otherEdge[0].X;
double y3 = otherEdge[0].Y;
double x4 = otherEdge[1].X;
double y4 = otherEdge[1].Y;
// get if inside both
double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));
if (0.05 < ua && ua < 0.95 && 0.5 < ub && ub < 0.95)
{
double x = x1 + ua * (x2 - x1);
double y = y1 + ua * (y2 - y1);
testPoints.Add(new Coordinates(x, y));
}
}
}
closed.Add(seg);
}
// loop through test points
foreach(Coordinates inner in testPoints)
{
// list of replacements
List<LinePath> toReplace = new List<LinePath>();
// loop through outer
foreach (LinePath edge in polyEdges)
{
//.........这里部分代码省略.........
示例4: IsEar
/// <summary>
/// Check if the triangle is an ear of the polygon
/// </summary>
/// <param name="triangle">Polygon consists of 3 points</param>
/// <param name="entirePolygon">Large polygon that triangle belongs to</param>
/// <returns></returns>
private bool IsEar(Polygon triangle, Polygon entirePolygon)
{
foreach (Vector2 v in entirePolygon)
{
// do not check on the points of triangle
if (triangle.Contains(v))
continue;
// check if this is an ear
if (triangle.IsInside(v))
return false;
}
return true;
}