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


C# Polygon.Inflate方法代码示例

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


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

示例1: GetPerimeterObstacles

        private List<Obstacle> GetPerimeterObstacles()
        {
            // transform the polygon to relative coordinates
            AbsoluteTransformer absTransform = Services.StateProvider.GetAbsoluteTransformer();

            Polygon relPerimeter = zonePerimeter.Transform(absTransform);
            LinePath relRecommendedPath = recommendedPath.Transform(absTransform);

            if (relPerimeter.IsCounterClockwise) {
                relPerimeter = relPerimeter.Reverse();
            }

            // create a polygon for ourselves and see if we intersect any perimeters
            Polygon vehiclePoly = new Polygon();
            vehiclePoly.Add(new Coordinates(-TahoeParams.RL, -(TahoeParams.T/2.0)));
            vehiclePoly.Add(new Coordinates(TahoeParams.FL, -(TahoeParams.T/2.0)));
            vehiclePoly.Add(new Coordinates(TahoeParams.FL, TahoeParams.T/2.0));
            vehiclePoly.Add(new Coordinates(-TahoeParams.RL, TahoeParams.T/2.0));
            // inflate by about 2 m
            vehiclePoly = vehiclePoly.Inflate(2);

            // test if we intersect any of the perimeter points
            List<Obstacle> perimeterObstacles = new List<Obstacle>();
            List<OperationalObstacle> operationalObstacles = new List<OperationalObstacle>();
            List<LineSegment> segments = new List<LineSegment>();
            foreach (LineSegment ls1 in relPerimeter.GetSegmentEnumerator()) {
                segments.Clear();
                if (ls1.Length > 15) {
                    // split into multiple segment
                    double targetLength = 10;
                    int numSegments = (int)Math.Round(ls1.Length/targetLength);
                    double splitLength = ls1.Length/numSegments;

                    Coordinates pt = ls1.P0;
                    for (int i = 0; i < numSegments; i++) {
                        Coordinates endPoint = pt + ls1.Vector.Normalize(splitLength);
                        LineSegment seg = new LineSegment(pt, endPoint);
                        segments.Add(seg);
                        pt = endPoint;
                    }
                }
                else {
                    segments.Add(ls1);
                }

                foreach (LineSegment ls in segments) {
                    bool pathTooClose = false;

                    foreach (Coordinates pt in relRecommendedPath) {
                        Coordinates closest = ls.ClosestPoint(pt);
                        if (closest.DistanceTo(pt) < 1)
                            pathTooClose = true;
                    }

                    if (!vehiclePoly.DoesIntersect(ls) && !pathTooClose) {
                        Obstacle obs = CreatePerimeterObstacle(ls);
                        perimeterObstacles.Add(obs);

                        OperationalObstacle uiobs = new OperationalObstacle();
                        uiobs.age = obs.age;
                        uiobs.heading = 0;
                        uiobs.headingValid = false;
                        uiobs.ignored = false;
                        uiobs.obstacleClass = obs.obstacleClass;
                        uiobs.poly = obs.obstaclePolygon;

                        operationalObstacles.Add(uiobs);
                    }
                }
            }

            Services.UIService.PushObstacles(operationalObstacles.ToArray(), curTimestamp, "perimeter obstacles", true);

            return perimeterObstacles;
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:75,代码来源:ZoneTravel.cs

示例2: UpdateIntersectionPolygon


//.........这里部分代码省略.........
            {
                // list of replacements
                List<LinePath> toReplace = new List<LinePath>();

                // loop through outer
                foreach (LinePath edge in polyEdges)
                {
                    // flag to replace
                    bool replace = false;

                    // make sure this goes to a valid edge section
                    LinePath.PointOnPath closest = edge.GetClosestPoint(inner);
                    if (!closest.Equals(edge.StartPoint) && !closest.Equals(edge.EndPoint) &&
                        !(closest.Location.DistanceTo(edge.StartPoint.Location)  < 0.5) &&
                        !(closest.Location.DistanceTo(edge.EndPoint.Location)  < 0.5))
                    {
                        // create seg (extend a bit)
                        Coordinates expansion = closest.Location - inner;
                        LinePath seg = new LinePath(new Coordinates[] { inner, closest.Location + expansion.Normalize(1.0) });

                        // set flag
                        replace = true;

                        // loop through other edges
                        foreach (LinePath otherEdge in other)
                        {
                            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.01 < ua && ua < 0.99 && 0 < ub && ub < 1)
                            {
                                replace = false;
                            }
                        }
                    }

                    // check if should replace
                    if (replace)
                    {
                        // add analyzed to adjacent
                        toReplace.Add(edge);
                    }
                }

                // loop through replacements
                foreach (LinePath ll in toReplace)
                {
                    LinePath[] tmpArrayPoly = new LinePath[polyEdges.Count];
                    polyEdges.CopyTo(tmpArrayPoly);
                    List<LinePath> tmpPoly = new List<LinePath>(tmpArrayPoly);

                    // get index of edge
                    int index = tmpPoly.IndexOf(ll);

                    // remove
                    tmpPoly.RemoveAt(index);

                    // add correctly to outer
                    tmpPoly.Insert(index, new LinePath(new Coordinates[] { ll[0], inner }));
                    tmpPoly.Insert(index + 1, new LinePath(new Coordinates[] { inner, ll[1] }));

                    // poly
                    Polygon temp = new Polygon();
                    foreach(LinePath lpTemp in tmpPoly)
                        temp.Add(lpTemp[1]);
                    temp.Inflate(0.5);

                    // make sure none of original outside
                    bool ok = true;
                    foreach (LinePath lp in other)
                    {
                        if (!temp.IsInside(lp[1]) && !temp.Contains(lp[1]))
                            ok = false;
                    }

                    // set if created ok
                    if (ok)
                        polyEdges = tmpPoly;
                }
            }

            // create final
            List<Coordinates> finalPoly = new List<Coordinates>();
            foreach (LinePath outerEdge in polyEdges)
                finalPoly.Add(outerEdge[1]);
            interPoly = new Polygon(finalPoly);

            aInt.IntersectionPolygon = interPoly;
            aInt.Center = interPoly.GetCentroid();
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:101,代码来源:IntersectionPulloutTool.cs


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