예제 #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)
            {
                //ERROR!
            }
        }
예제 #2
0
        public CPolygon(CPoint2D[] points)
        {
            int nNumOfPoitns = points.Length;

            try
            {
                if (nNumOfPoitns < 3)
                {
                    InvalidInputGeometryDataException ex =
                        new InvalidInputGeometryDataException();
                    throw ex;
                }
                else
                {
                    m_aVertices = new CPoint2D[nNumOfPoitns];
                    for (int i = 0; i < nNumOfPoitns; i++)
                    {
                        m_aVertices[i] = points[i];
                    }
                }
            }
            catch (Exception e)
            {
                //ERROR!
            }
        }
예제 #3
0
        private void Initialize(Double angleInRad, CPoint2D point)
        {
            //angleInRad should be between 0-Pi

            try
            {
                //if ((angleInRad<0) ||(angleInRad>Math.PI))
                if (angleInRad > 2 * Math.PI)
                {
                    string errMsg = string.Format(
                        "The input line angle" +
                        " {0} is wrong. It should be between 0-2*PI.", angleInRad);

                    InvalidInputGeometryDataException ex = new
                                                           InvalidInputGeometryDataException(errMsg);

                    throw ex;
                }

                if (Math.Abs(angleInRad - Math.PI / 2) <
                    ConstantValue.SmallValue)                     //vertical line
                {
                    a = 1;
                    b = 0;
                    c = -point.X;
                }
                else                 //not vertical line
                {
                    a = -Math.Tan(angleInRad);
                    b = 1;
                    c = -a * point.X - b * point.Y;
                }
            }
            catch (Exception e)
            {
                //ERROR!
            }
        }