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


C# Polygon.GetCentroid方法代码示例

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


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

示例1: 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

示例2: GetIntersectionPullPath

        protected void GetIntersectionPullPath(LinePath startingPath, LinePath endingPath, Polygon intersectionPolygon, bool addStartingPoint, bool addEndingPoint, LinePath targetPath, ref double pullWeight)
        {
            double angle = Math.Acos(startingPath.EndSegment.UnitVector.Dot(endingPath.GetSegment(0).UnitVector));

            // get the centroid of the intersection
            Coordinates centroid;

            // check if the angle is great than an threshold
            if (angle > 10*Math.PI/180.0) {
                // intersect the two lines formed by the starting and ending lanes
                Line startingLaneLine = new Line(startingPath[startingPath.Count-2], startingPath[startingPath.Count-1]);
                Line endingLaneLine = new Line(endingPath[1], endingPath[0]);

                // intersect them stuff and see if the point of intersection is between the two lines
                Coordinates K;
                if (!startingLaneLine.Intersect(endingLaneLine, out centroid, out K) || K.X <= 0 || K.Y <= 0)
                    return;
            }
            else {
                // if there is no intersection polygon, there isn't much we can do
                if (intersectionPolygon == null || intersectionPolygon.Count < 3) {
                    return;
                }

                centroid = intersectionPolygon.GetCentroid();
            }

            // calculate the pull weighting dependent on angle of intersection
            // angle 0 -> 0 weighting
            // angle 45 -> 0.00025 weighting
            // angle 90 -> 0.001 weighting
            pullWeight = Math.Pow(angle/(Math.PI/2), 2)*0.001;

            // get the relative transform from the behavior timestamp to the current timestamp
            RelativeTransform transform = Services.RelativePose.GetTransform(behaviorTimestamp, curTimestamp);
            centroid = transform.TransformPoint(centroid);

            if (addStartingPoint) {
                targetPath.Add(startingPath.EndPoint.Location);
            }
            // add the line from exit -> centroid (assuming that exit is already in the target path)
            targetPath.Add(centroid);
            if (addEndingPoint) {
                // add the line from centroid -> entrance
                targetPath.Add(endingPath[0]);
            }

            Services.UIService.PushLineList(targetPath, curTimestamp, "intersection path", true);
            Services.Dataset.ItemAs<double>("intersection weight").Add(pullWeight, curTimestamp);
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:50,代码来源:PlanningBase.cs


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