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


C# Point2D.MagnitudeSquared方法代码示例

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


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

示例1: PolygonsAreSame2D

        /// <summary>
        /// Check if the polys are similar to within a tolerance (Doesn't include reflections,
        /// but allows for the points to be numbered differently, but not reversed).
        /// </summary>
        /// <param name="poly1"></param>
        /// <param name="poly2"></param>
        /// <returns></returns>
        public static bool PolygonsAreSame2D(IList<Point2D> poly1, IList<Point2D> poly2)
        {
            int numVerts1 = poly1.Count;
            int numVerts2 = poly2.Count;

            if (numVerts1 != numVerts2)
            {
                return false;
            }
            const double kEpsilon = 0.01;
            const double kEpsilonSq = kEpsilon * kEpsilon;

            // Bounds the same to within tolerance, are there polys the same?
            Point2D vdelta = new Point2D(0.0, 0.0);
            for (int k = 0; k < numVerts2; ++k)
            {
                // Look for a match in verts2 to the first vertex in verts1
                vdelta.Set(poly1[0]);
                vdelta.Subtract(poly2[k]);

                if (vdelta.MagnitudeSquared() < kEpsilonSq)
                {
                    // Found match to the first point, now check the other points continuing round
                    // if the points don't match in the first direction we check, then it's possible
                    // that the polygons have a different winding order, so we check going round 
                    // the opposite way as well
                    int matchedVertIndex = k;
                    bool bReverseSearch = false;
                    while (true)
                    {
                        bool bMatchFound = true;
                        for (int i = 1; i < numVerts1; ++i)
                        {
                            if (!bReverseSearch)
                            {
                                ++k;
                            }
                            else
                            {
                                --k;
                                if (k < 0)
                                {
                                    k = numVerts2 - 1;
                                }
                            }

                            vdelta.Set(poly1[i]);
                            vdelta.Subtract(poly2[k % numVerts2]);
                            if (vdelta.MagnitudeSquared() >= kEpsilonSq)
                            {
                                if (bReverseSearch)
                                {
                                    // didn't find a match going in either direction, so the polygons are not the same
                                    return false;
                                }
                                else
                                {
                                    // mismatch in the first direction checked, so check the other direction.
                                    k = matchedVertIndex;
                                    bReverseSearch = true;
                                    bMatchFound = false;
                                    break;
                                }
                            }
                        }

                        if (bMatchFound)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
开发者ID:JapaMala,项目名称:armok-vision,代码行数:83,代码来源:PolygonUtil.cs


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