コード例 #1
0
        private static bool RecordEars(EarPolygon poly)
        {
            LinkedListNode <EarPoint> active = poly.Get();
            int NumPoints = poly.NumPoints() - 2;

            while (poly.NumPoints() >= 3)
            {
                int num = poly.NumPoints();
                int idx = active.Value.mIndex;
                do
                {
                    if (IsConvex(active, poly))
                    {
                        if (IsEar(active, poly))
                        {
                            break;
                        }
                    }
                    active = poly.Next(active);
                } while (idx != active.Value.mIndex);

                poly.AddResult(poly.Previous(active).Value[0], poly.Previous(active).Value[1], active.Value[0], active.Value[1], poly.Next(active).Value[0], poly.Next(active).Value[1]);
                active = poly.Next(active);
                poly.Remove(poly.Previous(active));
                continue;
            }
            return(true);
        }
コード例 #2
0
        private static bool RecordEars(EarPolygon poly)
        {
            LinkedListNode <EarPoint> active = poly.Get();
            int NumPoints = poly.NumPoints() - 2;

            while (poly.NumPoints() >= 3)
            {
                int num = poly.NumPoints();
                int idx = active.Value.mIndex;
                //do
                //{
                //    if (IsConvex(active, poly))
                //    {
                //        if (IsEar(active, poly))
                //        {
                //            break;
                //        }
                //    }
                //    active = poly.Next(active);
                //} while (idx != active.Value.mIndex);

                List <LinkedListNode <EarPoint> > candidate = new List <LinkedListNode <EarPoint> >();
                do
                {
                    if (IsConvex(active, poly))
                    {
                        if (IsEar(active, poly))
                        {
                            candidate.Add(active);
                        }
                    }
                    active = poly.Next(active);
                } while (idx != active.Value.mIndex);
                List <KeyValuePair <int, float> > temp = new List <KeyValuePair <int, float> >();
                for (int i = 0; i < candidate.Count; ++i)
                {
                    LinkedListNode <EarPoint> ear = candidate[i];
                    float angle = AngleWithUp(ear, poly);
                    temp.Add(new KeyValuePair <int, float>(i, angle));
                }
                temp.Sort((x, y) => { return(-x.Value.CompareTo(y.Value)); });
                active = candidate[temp[0].Key];
                temp.Clear();
                candidate.Clear();
                poly.AddResult(poly.Previous(active).Value.mPoint, active.Value.mPoint, poly.Next(active).Value.mPoint);
                poly.AddResult(poly.Previous(active).Value.mVertex, active.Value.mVertex, poly.Next(active).Value.mVertex);
                active = poly.Next(active);
                poly.Remove(poly.Previous(active));
                continue;
            }
            return(true);
        }
コード例 #3
0
        private static bool IsEar(LinkedListNode <EarPoint> ele, EarPolygon poly)
        {
            LinkedListNode <EarPoint> checkerN1 = poly.Next(ele);
            LinkedListNode <EarPoint> checker   = poly.Next(checkerN1);

            while (checker.Value.mIndex != poly.Previous(ele).Value.mIndex)
            {
                if (InTriangle(checker.Value, ele.Value, poly.Next(ele).Value, poly.Previous(ele).Value))
                {
                    return(false);
                }
                checker = poly.Next(checker);
            }
            return(true);
        }
コード例 #4
0
        private static bool IsConvex(LinkedListNode <EarPoint> ele, EarPolygon poly)
        {
            LinkedListNode <EarPoint> a = poly.Previous(ele);
            LinkedListNode <EarPoint> b = ele;
            LinkedListNode <EarPoint> c = poly.Next(ele);

            return(GeoPolygonUtils.IsConvex(a.Value.mPoint, b.Value.mPoint, c.Value.mPoint));
        }
コード例 #5
0
        private static bool IsInSegment(LinkedListNode <EarPoint> ele, EarPolygon poly)
        {
            LinkedListNode <EarPoint> a = poly.Previous(ele);
            LinkedListNode <EarPoint> b = ele;
            LinkedListNode <EarPoint> c = poly.Next(ele);

            return(GeoSegmentUtils.IsPointInSegment2(a.Value.mPoint, c.Value.mPoint, ref b.Value.mPoint));
        }
コード例 #6
0
        private static float AngleWithUp(LinkedListNode <EarPoint> ele, EarPolygon poly)
        {
            LinkedListNode <EarPoint> a = poly.Previous(ele);
            LinkedListNode <EarPoint> b = ele;
            LinkedListNode <EarPoint> c = poly.Next(ele);
            Vector3 ab    = a.Value.mVertex - b.Value.mVertex;
            Vector3 cb    = c.Value.mVertex - b.Value.mVertex;
            float   angle = Vector3.Angle(ab, cb);

            if (angle > 90)
            {
                angle = 180 - angle;
            }
            return(angle);
        }