/// <summary> /// Get the parametres of the points on line segment. (between 0 t0 1) /// </summary> /// <param name="point">the point.</param> /// <returns>the parametre of the point on line segment.</returns> public double GetPosition(Point2D point) { if (point == FirstPoint) { return(0); } else if (point == LastPoint) { return(1); } else { Vector2D v1 = point - FirstPoint; Vector2D v2 = this.ToVector(); double d = Vector2D.Determinant(v1, v2); if (d < ZeroTolerance) { return(v1.Length / v2.Length); } else if (d >= ZeroTolerance) { return(double.PositiveInfinity); } else { return(double.NegativeInfinity); } } }
/// <summary> /// Whether the point is on the line. /// </summary> /// <param name="point">the point.</param> /// <returns>true if is on the line.</returns> public bool isOnLine(Point2D point) { if (point == FirstPoint || point == LastPoint) { return(true); } else { Vector2D v1 = point - FirstPoint; Vector2D v2 = LastPoint - point; return(Vector2D.Determinant(v1, v2) < ZeroTolerance); } }
/// <summary> /// Whether the line segment contains the point and the point is not on the terminal. /// </summary> /// <param name="point">the point.</param> /// <returns>true if truly contains.</returns> public bool TrulyContains(Point2D point) { Vector2D v1 = point - FirstPoint; Vector2D v2 = LastPoint - point; double d1 = v1 * v2; double d2 = Vector2D.Determinant(v1, v2); if ((d1 > ZeroTolerance) && Math.Abs(d2) < ZeroTolerance) { return(true); } else { return(false); } }