Esempio n. 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((float)Math.PI / 2, point1);
                }
                else if (Math.Abs(point1.Y - point2.Y) < ConstantValue.SmallValue) //Horizontal line
                {
                    Initialize(0, point1);
                }
                else //normal line
                {
                    float m          = (point2.Y - point1.Y) / (point2.X - point1.X);
                    float alphaInRad = (float)Math.Atan(m);
                    Initialize(alphaInRad, point1);
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Error creating CLine", e);
            }
        }
Esempio n. 2
0
    private void Initialize(float 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 = (float)-Math.Tan(angleInRad);
          b = 1;
          c = -a * point.X - b * point.Y;
        }
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Error("Error initializing CLine", e);
      }
    }
Esempio n. 3
0
        private void Initialize(float 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 = (float)-Math.Tan(angleInRad);
                    b = 1;
                    c = -a * point.X - b * point.Y;
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Error("Error initializing CLine", e);
            }
        }
Esempio n. 4
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((float)Math.PI / 2, point1);
        }
        else if (Math.Abs(point1.Y - point2.Y) < ConstantValue.SmallValue) //Horizontal line
        {
          Initialize(0, point1);
        }
        else //normal line
        {
          float m = (point2.Y - point1.Y) / (point2.X - point1.X);
          float alphaInRad = (float)Math.Atan(m);
          Initialize(alphaInRad, point1);
        }
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Error("Error creating CLine", e);
      }
    }