Exemple #1
0
        public bool Intersects(LineSegment2D otherLine, out Point2D intersectionPoint)
        {
            intersectionPoint = null;
            var linSolveResult = MatrixOperations.LinSolve(new[, ]
            {
                { Vector.X, -otherLine.Vector.X },
                { Vector.Y, -otherLine.Vector.Y }
            }, new[]
            {
                otherLine.Point.X - Point.X,
                otherLine.Point.Y - Point.Y
            }, out var isValid);

            if (!isValid)
            {
                return(false);
            }
            if (!linSolveResult.All(x => x.IsBetween(0, 1)))
            {
                return(false);
            }
            intersectionPoint = Point + (linSolveResult[0] * Vector).ToVector2D();
            return(true);
        }
Exemple #2
0
 public static double DistanceToLineSegment(this Point2D point, LineSegment2D lineSegment)
 {
     return(DistanceToLineSegment(point, lineSegment.Point, lineSegment.Point + lineSegment.Vector));
 }