Exemple #1
0
        public Vector2 GetEdgeIntersection(VoronoiEdge a, VoronoiEdge b)
        {
            double x = (b.G - a.G) / (a.F - b.F);
            double y = a.F * x + a.G;

            if ((x - a.Start.X) / a.Direction.X < 0)
            {
                return(Vector2.Zero);
            }
            if ((y - a.Start.Y) / a.Direction.Y < 0)
            {
                return(Vector2.Zero);
            }

            if ((x - b.Start.X) / b.Direction.X < 0)
            {
                return(Vector2.Zero);
            }
            if ((y - b.Start.Y) / b.Direction.Y < 0)
            {
                return(Vector2.Zero);
            }

            Vector2 p = new Vector2((float)x, (float)y);

            points.Add(p);
            return(p);
        }
Exemple #2
0
        public void InsertParabola(Vector2 p)
        {
            if (root == null)
            {
                root = new VoronoiParabola(p); return;
            }

            if (root.IsLeaf && root.Site.Y - p.Y < 1)
            {
                Vector2 fp = root.Site;
                root.IsLeaf = false;
                root.Left   = new VoronoiParabola(fp);
                root.Right  = new VoronoiParabola(p);
                Vector2 s = new Vector2((p.X + fp.X) / 2, (float)height);
                points.Add(s);
                if (p.X > fp.X)
                {
                    root.Edge = new VoronoiEdge(s, fp, p);
                }
                else
                {
                    root.Edge = new VoronoiEdge(s, p, fp);
                }
                Edges.Add(root.Edge);
                return;
            }
            VoronoiParabola par = GetParabolaByX(p.X);

            if (par.CEvent != null)
            {
                deleted.Add(par.CEvent);
                par.CEvent = null;
            }

            Vector2 start = new Vector2(p.X, (float)GetY(par.Site, p.X));

            points.Add(start);

            VoronoiEdge el = new VoronoiEdge(start, par.Site, p);
            VoronoiEdge er = new VoronoiEdge(start, p, par.Site);

            el.Neighbour = er;
            Edges.Add(el);

            par.Edge   = er;
            par.IsLeaf = false;

            VoronoiParabola p0 = new VoronoiParabola(par.Site);
            VoronoiParabola p1 = new VoronoiParabola(p);
            VoronoiParabola p2 = new VoronoiParabola(par.Site);

            par.Right     = p2;
            par.Left      = new VoronoiParabola();
            par.Left.Edge = el;

            par.Left.Left  = p0;
            par.Left.Right = p1;

            CheckCircle(p0);
            CheckCircle(p2);
        }