Пример #1
0
        public double DistanceTo(Line other)
        {
            var distances = new List <double>();

            distances.Add(other.DistanceTo(this.StartPoint));

            distances.Add(other.DistanceTo(this.EndPoint));

            distances.Add(this.DistanceTo(other.StartPoint));

            distances.Add(this.DistanceTo(other.EndPoint));

            distances.Add(this.StartPoint.DistanceTo(other.StartPoint));

            distances.Add(this.StartPoint.DistanceTo(other.EndPoint));

            distances.Add(this.EndPoint.DistanceTo(other.StartPoint));

            distances.Add(this.EndPoint.DistanceTo(other.EndPoint));

            double d9           = Math.Abs(LineToLineDistance(other));
            var    closestPoint = this.ClosestPointOnLine(other);
            var    t            = this.ParameterAtPoint(closestPoint);

            closestPoint = other.ClosestPointOnLine(this);
            var u        = other.ParameterAtPoint(closestPoint);
            var dot      = Math.Abs(this.Direction.Normalized().Dot(other.Direction.Normalized()));
            var parallel = dot == 1;

            if (!parallel && t >= 0 && t <= 1 && u >= 0 && u <= 1)
            {
                distances.Add(d9);
            }

            return(distances.Min());
        }
Пример #2
0
 public double DistanceTo(Line l)
 {
     return(l.DistanceTo(this));
 }