Beispiel #1
0
        public void AddEdge(Vertex a, Vertex b)
        {
            Edge edga = new Edge(a,b);
            //Edge edgb = new Edge(b,a);

            //if (!EdgeList.Contains(edga) && !EdgeList.Contains(edgb))
            //{
                EdgeList.Add(edga);
            //}
        }
Beispiel #2
0
        /// <summary>Tests if a point lies in the circumcircle of the triangle.</summary>
        /// <param name="point">A <see cref="Point"/>.</param>
        /// <returns>For a counterclockwise order of the vertices of the triangle, this test is 
        /// <list type ="bullet">
        /// <item>positive if <paramref name="point"/> lies inside the circumcircle.</item>
        /// <item>zero if <paramref name="point"/> lies on the circumference of the circumcircle.</item>
        /// <item>negative if <paramref name="point"/> lies outside the circumcircle.</item></list></returns>
        /// <remarks>The vertices of the triangle must be arranged in counterclockwise order or the result
        /// of this test will be reversed. This test ignores the z-coordinate of the vertices.</remarks>
        public double ContainsInCircumcircle(Vertex point)
        {
            double ax = this.Vertex1.X - point.X;
            double ay = this.Vertex1.Y - point.Y;
            double bx = this.Vertex2.X - point.X;
            double by = this.Vertex2.Y - point.Y;
            double cx = this.Vertex3.X - point.X;
            double cy = this.Vertex3.Y - point.Y;

            double det_ab = ax * by - bx * ay;
            double det_bc = bx * cy - cx * by;
            double det_ca = cx * ay - ax * cy;

            double a_squared = ax * ax + ay * ay;
            double b_squared = bx * bx + by * by;
            double c_squared = cx * cx + cy * cy;

            return a_squared * det_bc + b_squared * det_ca + c_squared * det_ab;
        }
Beispiel #3
0
        private void DoVertexDrawing(Point point)
        {
            Ellipse elps = BuildEllipse(point);
            Vertex vert = new Vertex((int)point.X, (int)point.Y);
            if (!vertices.ContainsValue(vert))
            {

                graph.AddVertex(vert);
                vertices.Add(elps, vert);

                AddUIElement(elps, 10);
            }
        }
Beispiel #4
0
        private void DoEdgeDrawing(Vertex a, Vertex b)
        {
            Line line = BuildLine(a, b, Colors.Gray);

            Edge edge = new Edge(a, b);
            if (!edges.ContainsValue(edge))
            {
                graph.AddEdge(a, b);
                edges.Add(line, edge);
                AddUIElement(line, -10);
            }
        }
Beispiel #5
0
 private void DoEdgeDrawing(Vertex point)
 {
     if (!isStartPointSet)
     {
         isStartPointSet = true;
         startVertex = point;
     }
     else
     {
         isStartPointSet = false;
         endVertex = point;
         DoEdgeDrawing(startVertex, endVertex);
     }
 }
Beispiel #6
0
        private Line BuildLine(Vertex a, Vertex b, Color color)
        {
            Line myLine = new Line();
            myLine.Stroke = new SolidColorBrush(color);
            //myLine.MouseEnter += new System.Windows.Input.MouseEventHandler(myLine_MouseEnter);
            if(color == Colors.Gray)
                myLine.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Line_MouseLeftButtonDown);
            myLine.StrokeThickness = 7;
            myLine.X1 = a.X;
            myLine.Y1 = a.Y;

            myLine.X2 = b.X;
            myLine.Y2 = b.Y;

            return myLine;
        }
Beispiel #7
0
 /// <summary>Constructs a triangle from three points.</summary>
 /// <param name="vertex1">The first vertex of the triangle.</param>
 /// <param name="vertex2">The second vertex of the triangle.</param>
 /// <param name="vertex3">The third vertex of the triangle.</param>
 public Triangle(Vertex vertex1, Vertex vertex2, Vertex vertex3)
 {
     this.Vertex1 = vertex1;
     this.Vertex2 = vertex2;
     this.Vertex3 = vertex3;
 }
Beispiel #8
0
 public void AddVertex(Vertex v)
 {
     VertexList.Add(v);
 }
Beispiel #9
0
        /// <summary>Returns a triangle that encompasses all triangulation points.</summary>
        /// <param name="triangulationPoints">A list of triangulation points.</param>
        /// <returns>Returns a triangle that encompasses all triangulation points.</returns>
        private Triangle SuperTriangle(List<Vertex> triangulationPoints)
        {
            double M = triangulationPoints[0].X;

            // get the extremal x and y coordinates
            for (int i = 1; i < triangulationPoints.Count; i++)
            {
                double xAbs = Math.Abs(triangulationPoints[i].X);
                double yAbs = Math.Abs(triangulationPoints[i].Y);
                if (xAbs > M) M = xAbs;
                if (yAbs > M) M = yAbs;
            }

            // make a triangle
            Vertex sp1 = new Vertex((int) (10 * M), 0);
            Vertex sp2 = new Vertex(0, (int) (10 * M));
            Vertex sp3 = new Vertex((int) (-10 * M), (int) (-10 * M));

            return new Triangle(sp1, sp2, sp3);
        }