示例#1
0
        public bool CalculateBreakpoint(float sweepLine)
        {
            VectorNode p = _leftListEvent.GetNode();
            VectorNode q = _rightListEvent.GetNode();

            float alpha = 0.5f / (p.y - sweepLine);
            float beta  = 0.5f / (q.y - sweepLine);
            float A     = alpha - beta;
            float B     = (-2.0f * (alpha * p.x - beta * q.x));
            float C     = (alpha * (p.y * p.y + p.x * p.x - sweepLine * sweepLine) - beta * (q.y * q.y
                                                                                             + q.x * q.x - sweepLine * sweepLine));

            if (p.y == q.y)
            {
                _x = -C / B;
                _y = (1.0f / (2.0f * (p.y - sweepLine))) * (((_x - p.x) * (_x - p.x)) +
                                                            p.y * p.y - sweepLine * sweepLine);
            }
            else
            {
                float disc = B * B - 4 * A * C;
                if (disc < 0)
                {
                    return(false);
                }
                _x = (-B + 1.0f * (float)Math.Sqrt(B * B - 4 * A * C)) / (2 * A);
                _y = (1.0f / (2.0f * (p.y - sweepLine))) * (((_x - p.x) * (_x - p.x)) +
                                                            p.y * p.y - sweepLine * sweepLine);
            }

            return(true);
        }
示例#2
0
        public bool RotateAndCalculateCircle(double degrees)
        {
            double COS = Math.Cos(degrees * Math.PI / 180);
            double SIN = Math.Sin(degrees * Math.PI / 180);

            VectorNode point1 = _left.GetNode();
            VectorNode point2 = _center.GetNode();
            VectorNode point3 = _right.GetNode();

            float p1x = (float)(COS * point1.x - SIN * point1.y);
            float p1y = (float)(SIN * point1.x + COS * point1.y);

            point1 = new VectorNode(p1x, p1y);

            float p2x = (float)(COS * point2.x - SIN * point2.y);
            float p2y = (float)(SIN * point2.x + COS * point2.y);

            point2 = new VectorNode(p2x, p2y);

            float p3x = (float)(COS * point3.x - SIN * point3.y);
            float p3y = (float)(SIN * point3.x + COS * point3.y);

            point3 = new VectorNode(p3x, p3y);



            double normal12;
            double normal23;


            double grad12 = (point2.y - point1.y) / (point2.x - point1.x);

            normal12 = -1.0 / grad12;


            double grad23 = (point3.y - point2.y) / (point3.x - point2.x);

            normal23 = -1.0 / grad23;


            double const12 = 0.5 * (point1.y + point2.y) - 0.5 * normal12 * (point1.x + point2.x);
            double const23 = 0.5 * (point2.y + point3.y) - 0.5 * normal23 * (point2.x + point3.x);


            double centerX = (const23 - const12) / (normal12 - normal23);
            double centerY = normal23 * centerX + const23;


            float radius1 = (float)Math.Sqrt((point1.x - centerX) * (point1.x - centerX) +
                                             (point1.y - centerY) * (point1.y - centerY));

            float centerX2 = (float)(COS * centerX + SIN * centerY);
            float centerY2 = (float)(-SIN * centerX + COS * centerY);

            _R = radius1;
            _X = centerX2;
            _Y = centerY2;

            return(true);
        }
示例#3
0
 public DelaunayEdge(VectorNode from, VectorNode to)
 {
     _from = from;
     _to   = to;
 }
示例#4
0
        private void GetFinalNodePoint(EventTree.TreeNode node)
        {
            if (node is EventTree.LeafNode)
            {
                if (((EventTree.LeafNode)node).GetBreakpointNode() == null)
                {
                    return;
                }
                Breakpoint b = ((EventTree.LeafNode)node).GetBreakpointNode().GetBreakpoint();


                VectorNode n1 = b.getLeftListEvent().GetHalfEdge().GetFace();
                VectorNode n2 = b.getLeftListEvent().GetHalfEdge().Twin().GetFace();


                float centerx = 0.5f * (b.getLeftListEvent().GetHalfEdge().GetFace().x + b.getLeftListEvent().GetHalfEdge().Twin().GetFace().x);
                float centery = 0.5f * (b.getLeftListEvent().GetHalfEdge().GetFace().y + b.getLeftListEvent().GetHalfEdge().Twin().GetFace().y);

                if (n1.y == n2.y)
                {
                    HalfEdge    he = b.getLeftListEvent().GetHalfEdge();
                    CircleEvent ce = new CircleEvent(centerx, -_openEdgeLimit /* neg infinity */);
                    if (he.GetTarget() == null)
                    {
                        he.SetTarget(ce);
                        ce.halfEdge = he;
                    }
                    else
                    {
                        he.Twin().SetTarget(ce);
                        ce.halfEdge = he.Twin();
                    }
                    _allCircleEvents.Add(ce);
                }
                else
                {
                    float grad     = (n2.y - n1.y) * 1.0f / (n2.x - n1.x);
                    float realGrad = -1.0f / grad;

                    float constant = centery - realGrad * centerx;

                    float bpx = b.getX() - centerx;
                    float bpy = b.getY() - centery;

                    //if x = bpx...
                    float       testx = centerx + 10000f;
                    float       testy = testx * realGrad + constant;
                    CircleEvent ce;
                    if (testx * bpx + testy * bpy > 0)
                    {
                        ce = new CircleEvent(testx, testy);
                    }
                    else
                    {
                        ce = new CircleEvent(centerx - 10000, (centerx - 10000) * realGrad + constant);
                    }


                    HalfEdge he = b.getLeftListEvent().GetHalfEdge();
                    if (he.GetFace() != b.getLeftListEvent().GetNode())
                    {
                        he = he.Twin();
                    }


                    if (he.GetTarget() == null)
                    {
                        he.SetTarget(ce);
                    }
                    else if (he.Twin().GetTarget() == null)
                    {
                        he.Twin().SetTarget(ce);
                    }
                    else
                    {
                        // big problem... should never happen
                    }
                    _allCircleEvents.Add(ce);
                }

                return;
            }
            else
            {
                Breakpoint b = ((EventTree.BreakpointNode)node).GetBreakpoint();

                b.CalculateBreakpoint(_openEdgeLimit);


                if (node.LChild() != null)
                {
                    GetFinalNodePoint(node.LChild());
                }
                if (node.RChild() != null)
                {
                    GetFinalNodePoint(node.RChild());
                }
            }
        }
示例#5
0
 public void SetFace(VectorNode node)
 {
     _face = node;
 }
示例#6
0
 public HalfEdge(VectorNode face)
 {
     SetFace(face);
 }
示例#7
0
 public TreeItem(VectorNode node)
 {
     this._point = node;
 }
示例#8
0
 public SiteEvent(VectorNode vector)
 {
     _vector = vector;
 }
示例#9
0
 public bool Equals(VectorNode other)
 {
     return(x == other.x && y == other.y);
 }
示例#10
0
        public bool CalculateCircle()
        {
            VectorNode point1  = _left.GetNode();
            VectorNode point2  = _center.GetNode();
            VectorNode point3  = _right.GetNode();
            float      epsilon = 0.000001f;

            if (point2.x == point3.x && point2.x == point1.x)
            {
                return(false);
            }
            else
            {
                double grad12 = (point2.y - point1.y) * 1f / (point2.x - point1.x);
                double grad23 = (point3.y - point2.y) * 1f / (point3.x - point2.x);

                if (Math.Abs(grad12 - grad23) < epsilon)
                {
                    return(false);
                }
            }

            double normal12;
            double normal23;

            if (point2.y == point3.y)
            {
                point1 = _right.GetNode();
                point3 = _left.GetNode();
            }
            if (Math.Abs(point2.x - point1.x) < epsilon || Math.Abs(point2.y - point1.y) < epsilon ||
                Math.Abs(point2.x - point3.x) < epsilon || Math.Abs(point2.y - point3.y) < epsilon ||
                Math.Abs(point1.x - point3.x) < epsilon || Math.Abs(point1.y - point3.y) < epsilon)
            {
                return(RotateAndCalculateCircle(11.3f));
            }

            else
            {
                if (Math.Abs(point2.x - point1.x) < epsilon || Math.Abs(point2.y - point1.y) < epsilon ||
                    Math.Abs(point2.x - point3.x) < epsilon || Math.Abs(point2.y - point3.y) < epsilon ||
                    Math.Abs(point1.x - point3.x) < epsilon || Math.Abs(point1.y - point3.y) < epsilon)
                {
                    return(RotateAndCalculateCircle(11.3));
                }
                else
                {
                    // first pair perpendicular bisector
                    double grad12 = (point2.y - point1.y) / (point2.x - point1.x);
                    normal12 = -1.0 / grad12;

                    double grad23 = (point3.y - point2.y) / (point3.x - point2.x);
                    normal23 = -1.0 / grad23;

                    double const12 = 0.5 * (point1.y + point2.y) - 0.5 * normal12 * (point1.x + point2.x);
                    double const23 = 0.5 * (point2.y + point3.y) - 0.5 * normal23 * (point2.x + point3.x);


                    double centerX = (const23 - const12) / (normal12 - normal23);
                    double centerY = normal23 * centerX + const23;


                    float radius1 = (float)Math.Sqrt((point1.x - centerX) * (point1.x - centerX) +
                                                     (point1.y - centerY) * (point1.y - centerY));

                    _R = radius1;
                    _X = (float)centerX;
                    _Y = (float)centerY;
                }
            }

            return(true);
        }