当前位置: 首页>>代码示例>>C#>>正文


C# Polygon.AddRange方法代码示例

本文整理汇总了C#中Polygon.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.AddRange方法的具体用法?C# Polygon.AddRange怎么用?C# Polygon.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon的用法示例。


在下文中一共展示了Polygon.AddRange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateConvexHull

		public static Polygon CreateConvexHull(this Polygons polygons)
		{
			Polygon allPoints = new Polygon();
			foreach (Polygon polygon in polygons)
			{
				allPoints.AddRange(polygon);
			}

			return allPoints.CreateConvexHull();
		}
开发者ID:GearWalker,项目名称:MatterSlice,代码行数:10,代码来源:PolygonsHelper.cs

示例2: 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)
                {
//.........这里部分代码省略.........
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:101,代码来源:IntersectionPulloutTool.cs

示例3: ProjectRectangle

        public Polygon ProjectRectangle(Rectangle rectangle)
        {
            Polygon polygon = new Polygon();

            // get corners counter clockwise starting on the top left and project them to create the polygon:
            polygon.AddRange(new Point[] {
                new Point(rectangle.X, rectangle.Y), // top left
                new Point(rectangle.X, rectangle.Y + rectangle.Height), // bottom left
                new Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), // bottom right
                new Point(rectangle.X + rectangle.Width, rectangle.Y) // top right
            }.Select(ProjectPoint));
            return polygon;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:13,代码来源:TextureProjectionQuad.cs

示例4: GenerateInterconnectPolygon

        public void GenerateInterconnectPolygon(ArbiterInterconnect ai)
        {
            List<Coordinates> polyPoints = new List<Coordinates>();
            try
            {
                // width
                double width = 3.0;
                if (ai.InitialGeneric is ArbiterWaypoint)
                {
                    ArbiterWaypoint aw = (ArbiterWaypoint)ai.InitialGeneric;
                    width = width < aw.Lane.Width ? aw.Lane.Width : width;
                }
                if (ai.FinalGeneric is ArbiterWaypoint)
                {
                    ArbiterWaypoint aw = (ArbiterWaypoint)ai.FinalGeneric;
                    width = width < aw.Lane.Width ? aw.Lane.Width : width;
                }

                if (ai.TurnDirection == ArbiterTurnDirection.UTurn ||
                    ai.TurnDirection == ArbiterTurnDirection.Straight ||
                    !(ai.InitialGeneric is ArbiterWaypoint) ||
                    !(ai.FinalGeneric is ArbiterWaypoint))
                {
                    LinePath lp = ai.InterconnectPath.ShiftLateral(width / 2.0);
                    LinePath rp = ai.InterconnectPath.ShiftLateral(-width / 2.0);
                    polyPoints.AddRange(lp);
                    polyPoints.AddRange(rp);
                    ai.TurnPolygon = Polygon.GrahamScan(polyPoints);

                    if (ai.TurnDirection == ArbiterTurnDirection.UTurn)
                    {
                        List<Coordinates> updatedPts = new List<Coordinates>();
                        LinePath interTmp = ai.InterconnectPath.Clone();
                        Coordinates pathVec = ai.FinalGeneric.Position - ai.InitialGeneric.Position;
                        interTmp[1] = interTmp[1] + pathVec.Normalize(width / 2.0);
                        interTmp[0] = interTmp[0] - pathVec.Normalize(width / 2.0);
                        lp = interTmp.ShiftLateral(TahoeParams.VL);
                        rp = interTmp.ShiftLateral(-TahoeParams.VL);
                        updatedPts.AddRange(lp);
                        updatedPts.AddRange(rp);
                        ai.TurnPolygon = Polygon.GrahamScan(updatedPts);
                    }
                }
                else
                {
                    // polygon points
                    List<Coordinates> interPoints = new List<Coordinates>();

                    // waypoint
                    ArbiterWaypoint awI = (ArbiterWaypoint)ai.InitialGeneric;
                    ArbiterWaypoint awF = (ArbiterWaypoint)ai.FinalGeneric;

                    // left and right path
                    LinePath leftPath = new LinePath();
                    LinePath rightPath = new LinePath();

                    // some initial points
                    LinePath initialPath = new LinePath(new Coordinates[] { awI.PreviousPartition.Initial.Position, awI.Position });
                    LinePath il = initialPath.ShiftLateral(width / 2.0);
                    LinePath ir = initialPath.ShiftLateral(-width / 2.0);
                    leftPath.Add(il[1]);
                    rightPath.Add(ir[1]);

                    // some final points
                    LinePath finalPath = new LinePath(new Coordinates[] { awF.Position, awF.NextPartition.Final.Position });
                    LinePath fl = finalPath.ShiftLateral(width / 2.0);
                    LinePath fr = finalPath.ShiftLateral(-width / 2.0);
                    leftPath.Add(fl[0]);
                    rightPath.Add(fr[0]);

                    // initial and final paths
                    Line iPath = new Line(awI.PreviousPartition.Initial.Position, awI.Position);
                    Line fPath = new Line(awF.Position, awF.NextPartition.Final.Position);

                    // get where the paths intersect and vector to normal path
                    Coordinates c;
                    iPath.Intersect(fPath, out c);
                    Coordinates vector = ai.InterconnectPath.GetClosestPoint(c).Location - c;
                    Coordinates center = c + vector.Normalize((vector.Length / 2.0));

                    // get width expansion
                    Coordinates iVec = awI.PreviousPartition != null ? awI.PreviousPartition.Vector().Normalize(1.0) : awI.NextPartition.Vector().Normalize(1.0);
                    double iRot = -iVec.ArcTan;
                    Coordinates fVec = awF.NextPartition != null ? awF.NextPartition.Vector().Normalize(1.0) : awF.PreviousPartition.Vector().Normalize(1.0);
                    fVec = fVec.Rotate(iRot);
                    double fDeg = fVec.ToDegrees();
                    double arcTan = Math.Atan2(fVec.Y, fVec.X) * 180.0 / Math.PI;
                    double centerWidth = width + width * 2.0 * Math.Abs(arcTan) / 90.0;

                    // get inner point (small scale)
                    Coordinates innerPoint = center + vector.Normalize(centerWidth / 4.0);

                    // get outer
                    Coordinates outerPoint = center - vector.Normalize(centerWidth / 2.0);

                    if (ai.TurnDirection == ArbiterTurnDirection.Right)
                    {
                        rightPath.Insert(1, innerPoint);
                        ai.InnerCoordinates = rightPath;
                        leftPath.Reverse();
//.........这里部分代码省略.........
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:101,代码来源:InterconnectGeneration.cs


注:本文中的Polygon.AddRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。