示例#1
0
        public CLine(CPoint2D point1, CPoint2D point2)
        {
            try
            {
                if (CPoint2D.SamePoints(point1, point2))
                {
                    string errMsg = "The input points are the same";
                    InvalidInputGeometryDataException ex = new
                                                           InvalidInputGeometryDataException(errMsg);
                    throw ex;
                }

                //Point1 and Point2 are different points:
                if (Math.Abs(point1.X - point2.X)
                    < ConstantValue.SmallValue)                    //vertical line
                {
                    Initialize(Math.PI / 2, point1);
                }
                else if (Math.Abs(point1.Y - point2.Y)
                         < ConstantValue.SmallValue)               //Horizontal line
                {
                    Initialize(0, point1);
                }
                else                 //normal line
                {
                    double m          = (point2.Y - point1.Y) / (point2.X - point1.X);
                    double alphaInRad = Math.Atan(m);
                    Initialize(alphaInRad, point1);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message + e.StackTrace);
            }
        }
示例#2
0
        /***********************************
        *  From a given point, get its vertex index.
        *  If the given point is not a polygon vertex,
        *  it will return -1
        ***********************************/
        public int VertexIndex(CPoint2D vertex)
        {
            int nIndex = -1;

            int nNumPts = m_aVertices.Length;

            for (int i = 0; i < nNumPts; i++)         //each vertex
            {
                if (CPoint2D.SamePoints(m_aVertices[i], vertex))
                {
                    nIndex = i;
                }
            }
            return(nIndex);
        }