Exemplo n.º 1
0
        private void CheckCircleEvent(VParabola parabola)
        {
            VEdge leftEdge  = parabola.LeftEdge;
            VEdge rightEdge = parabola.RightEdge;

            if (!VEdge.HasValidIntersectPoint(leftEdge, rightEdge))
            {
                return;
            }

            Vector3 intersectPoint = VEdge.GetIntersectPoint(leftEdge, rightEdge);

            float distance = Vector3.Distance(intersectPoint, parabola.FocusPoint);
            float targetLy = intersectPoint.z - distance;

            Vector3 circlePoint = new Vector3(parabola.FocusPoint.x, 0, targetLy);

            VEvent algorithmEvent = new VEvent(circlePoint, false);

            algorithmEvent.Parabola    = parabola;
            algorithmEvent.VertexPoint = intersectPoint;

            parabola.CircleEvent = algorithmEvent;

            m_eventQueues.Add(algorithmEvent);
            SortEventQueues();
        }
Exemplo n.º 2
0
        public VoronoiDiagram(Vector3[] inputPoints, VBorder border)
        {
            m_border    = border;
            m_parabolas = new List <VParabola>();
            Edges       = new List <VEdge>();
            Vertices    = new List <Vector3>();

            m_eventQueues = new List <VEvent>();
            for (int i = 0; i < inputPoints.Length; i++)
            {
                m_eventQueues.Add(new VEvent(inputPoints[i], true));
            }
            SortEventQueues();

            while (m_eventQueues.Count > 0)
            {
                VEvent currentEvent = m_eventQueues[0];
                m_eventQueues.RemoveAt(0);

                m_ly = currentEvent.Site.z;

                if (currentEvent.IsSiteEvent)
                {
                    AddSiteEvent(currentEvent.Site, m_ly);
                }
                else
                {
                    AddCircleEvent(currentEvent);
                }
            }

            FinishEdge();
        }
Exemplo n.º 3
0
        private void AddCircleEvent(VEvent algorithmEvent)
        {
            List <VParabola> removeParabolas = new List <VParabola>();
            VParabola        removeParabola  = algorithmEvent.Parabola;

            VParabola leftParabola  = removeParabola.LeftParabola;
            VParabola rightParabola = removeParabola.RightParabola;

            if (leftParabola == null || rightParabola == null)
            {
                return;
            }

            removeParabolas.Add(removeParabola);

            if (removeParabolas.Count == 0)
            {
                return;
            }

            if (leftParabola.CircleEvent != null)
            {
                m_eventQueues.Remove(leftParabola.CircleEvent);
                leftParabola.CircleEvent = null;
            }

            if (rightParabola.CircleEvent != null)
            {
                m_eventQueues.Remove(rightParabola.CircleEvent);
                rightParabola.CircleEvent = null;
            }

            Vertices.Add(algorithmEvent.VertexPoint);

            VEdge edge = new VEdge(algorithmEvent.VertexPoint, leftParabola.FocusPoint, rightParabola.FocusPoint);

            Edges.Add(edge);

            leftParabola.RightParabola = rightParabola;
            leftParabola.RightEdge     = edge;

            rightParabola.LeftParabola = leftParabola;
            rightParabola.LeftEdge     = edge;

            for (int i = 0; i < removeParabolas.Count; i++)
            {
                m_eventQueues.Remove(removeParabolas[i].CircleEvent);
                removeParabolas[i].CircleEvent = null;
                removeParabolas[i].LeftEdge.SetVertexPoint(algorithmEvent.VertexPoint);
                removeParabolas[i].RightEdge.SetVertexPoint(algorithmEvent.VertexPoint);
                m_parabolas.Remove(removeParabolas[i]);
            }

            CheckCircleEvent(leftParabola);
            CheckCircleEvent(rightParabola);
        }