Exemplo n.º 1
0
        public List <EPMTriangle> ExtractTriangles_PointsInCircle(Vector2d origin, double radius, int pointCount = 1, List <EPMTriangle> waitingProcessList = null)
        {
            List <EPMTriangle> extractList = new List <EPMTriangle>();

            if (waitingProcessList == null)
            {
                waitingProcessList = g_triangleList;
            }
            for (int i = 0; i < waitingProcessList.Count; i++)
            {
                EPMTriangle     t     = waitingProcessList[i];
                List <EPMPoint> plist = t.g_pointList;
                int             count = 0;
                for (int j = 0; j < plist.Count; j++)
                {
                    Vector2d v2       = plist[j].pos2d - origin;
                    double   distance = v2.Length();
                    if (distance <= radius)
                    {
                        count++;
                        if (count >= pointCount)
                        {
                            extractList.Add(t);
                            break;
                        }
                    }
                }
            }
            return(extractList);
        }
Exemplo n.º 2
0
        //if 2 points are shared, they must share one edge
        public bool GetShareEdge(EPMTriangle t2, out int point1Index, out int point2Index)
        {
            point1Index = point2Index = -1;
            if (t2.g_sortedIndexList[0] == g_sortedIndexList[0] || t2.g_sortedIndexList[0] == g_sortedIndexList[1] || t2.g_sortedIndexList[0] == g_sortedIndexList[2])
            {
                point1Index = t2.g_sortedIndexList[0];
            }

            if (t2.g_sortedIndexList[1] == g_sortedIndexList[0] || t2.g_sortedIndexList[1] == g_sortedIndexList[1] || t2.g_sortedIndexList[1] == g_sortedIndexList[2])
            {
                if (point1Index == -1)
                {
                    point1Index = t2.g_sortedIndexList[1];
                }
                else
                {
                    point2Index = t2.g_sortedIndexList[1];
                }
            }

            if (t2.g_sortedIndexList[2] == g_sortedIndexList[0] || t2.g_sortedIndexList[2] == g_sortedIndexList[1] || t2.g_sortedIndexList[2] == g_sortedIndexList[2])
            {
                point2Index = t2.g_sortedIndexList[2];
            }
            return(point2Index != -1);
        }
Exemplo n.º 3
0
 private void AddTriangleByPointIndex(int index, EPMTriangle t)
 {
     if (m_pointIndexToTriangleList[index] == null)
     {
         m_pointIndexToTriangleList[index] = new List <EPMTriangle>();
     }
     m_pointIndexToTriangleList[index].Add(t);
 }
Exemplo n.º 4
0
        public override void StartGenerating()
        {
            g_triangleList             = EPMDelaunayAlgorithm.DoDelaunay(m_vertexList, g_startPoint, g_endPoint);
            m_pointIndexToTriangleList = new List <EPMTriangle> [m_vertexList.Count];

            for (int i = 0; i < g_triangleList.Count; i++)
            {
                EPMTriangle t = g_triangleList[i];
                t.TryDetermineType();
                AddTriangleByPointIndex(t[0].g_indexInList, t);
                AddTriangleByPointIndex(t[1].g_indexInList, t);
                AddTriangleByPointIndex(t[2].g_indexInList, t);
            }
            CalculateTriangleNeighbor();
        }
Exemplo n.º 5
0
        //For each triangle, find its neighbors, note that there are 2 types of neighbors, sharedEdge neighbors and sharedPoint neighbors. the TidyNeighbor() function would do the classification.
        private void CalculateTriangleNeighbor()
        {
            for (int i = 0; i < g_triangleList.Count; i++)
            {
                EPMTriangle     t        = g_triangleList[i];
                List <EPMPoint> vertices = t.g_pointList;

                for (int j = 0; j < vertices.Count; j++)
                {
                    List <EPMTriangle> shared = m_pointIndexToTriangleList[vertices[j].g_indexInList];
                    for (int k = 0; k < shared.Count; k++)
                    {
                        t.g_sharePointNeighbors.Add(shared[k]);
                    }
                }
                t.TidyNeighbors();
            }
        }
Exemplo n.º 6
0
        //It is not accurate, but it can extract most triangles and it is simple&fast
        public List <EPMTriangle> ExtractTriangles_IntersectLine(Vector2d lineStart, Vector2d lineEnd, List <EPMTriangle> waitingProcessList = null)
        {
            List <EPMTriangle> extractList = new List <EPMTriangle>();

            if (waitingProcessList == null)
            {
                waitingProcessList = g_triangleList;
            }
            Vector2d dir        = lineEnd - lineStart;
            double   lineLength = dir.Length();

            dir.Normalize();
            Vector2d normal = new Vector2d(-dir.y, dir.x);

            for (int i = 0; i < waitingProcessList.Count; i++)
            {
                EPMTriangle     t     = waitingProcessList[i];
                List <EPMPoint> plist = t.g_pointList;
                int             side  = 0;
                for (int j = 0; j < plist.Count; j++)
                {
                    Vector2d v2  = plist[j].pos2d - lineStart;
                    double   dot = v2 * dir;
                    if (dot < 0 || dot > lineLength)
                    {
                        continue;
                    }

                    double distance = v2 * normal;
                    if (side == 0)
                    {
                        side = distance > 0 ? 1 : -1;
                    }
                    else if (side * distance < 0)
                    {
                        extractList.Add(t);
                        break;
                    }
                }
            }
            return(extractList);
        }
Exemplo n.º 7
0
        public List <EPMTriangle> ExtractTriangles_PointsInLineWithDistance(Vector2d lineStart, Vector2d lineEnd, double halfWidth, int pointCount = 1, List <EPMTriangle> waitingProcessList = null)
        {
            List <EPMTriangle> extractList = new List <EPMTriangle>();

            if (waitingProcessList == null)
            {
                waitingProcessList = g_triangleList;
            }
            Vector2d dir        = lineEnd - lineStart;
            double   lineLength = dir.Length();

            dir.Normalize();
            Vector2d normal = new Vector2d(-dir.y, dir.x);

            for (int i = 0; i < waitingProcessList.Count; i++)
            {
                EPMTriangle     t     = waitingProcessList[i];
                List <EPMPoint> plist = t.g_pointList;

                int count = 0;
                for (int j = 0; j < plist.Count; j++)
                {
                    Vector2d v2       = plist[j].pos2d - lineStart;
                    double   dot      = v2 * dir;
                    double   distance = v2 * normal;
                    if (dot >= 0 && dot <= lineLength && System.Math.Abs(distance) <= halfWidth)
                    {
                        count++;
                        if (count >= pointCount)
                        {
                            extractList.Add(t);
                            break;
                        }
                    }
                }
            }
            return(extractList);
        }