public LineEquation(Coordinate point1, Coordinate point2) { if (point1 == null) { throw new ArgumentNullException("point1"); } if (point2 == null) { throw new ArgumentNullException("point2"); } try { if (point1.Equals(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 ex) { ExceptionManager.Publish(ex); throw; } }
private void Initialize(Double angleInRad, Coordinate point) { //angleInRad should be between 0-Pi try { //if ((angleInRad<0) ||(angleInRad>Math.PI)) if (angleInRad > 2 * Math.PI) { string errMsg = string.Format( CultureInfo.InvariantCulture.NumberFormat, "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 ex) { ExceptionManager.Publish(ex); throw; } }