示例#1
0
        /// <summary>
        /// Get closes points between lines.
        /// </summary>
        public (Vector3, Vector3) ClosestPointsBetween(Line3D other, bool mustBeOnSegments)
        {
            if (!IsParallelTo(other) || !mustBeOnSegments)
            {
                var pair = ClosestPointsBetween(other);
                if (!mustBeOnSegments)
                {
                    return(pair);
                }

                if ((pair.Item1 - StartPoint).Length() <= GetLength() &&
                    (pair.Item1 - EndPoint).Length() <= GetLength() &&
                    (pair.Item2 - other.StartPoint).Length() <= other.GetLength() &&
                    (pair.Item2 - other.EndPoint).Length() <= other.GetLength())
                {
                    return(pair);
                }
            }

            var checkPoint  = other.ClosestPointTo(StartPoint, true);
            var distance    = (checkPoint - StartPoint).Length();
            var closestPair = (StartPoint, checkPoint);
            var minDistance = distance;

            checkPoint = other.ClosestPointTo(EndPoint, true);
            distance   = (checkPoint - EndPoint).Length();
            if (distance < minDistance)
            {
                closestPair = (EndPoint, checkPoint);
                minDistance = distance;
            }

            checkPoint = ClosestPointTo(other.StartPoint, true);
            distance   = (checkPoint - other.StartPoint).Length();
            if (distance < minDistance)
            {
                closestPair = (checkPoint, other.StartPoint);
                minDistance = distance;
            }

            checkPoint = ClosestPointTo(other.EndPoint, true);
            distance   = (checkPoint - other.EndPoint).Length();
            if (distance < minDistance)
            {
                closestPair = (checkPoint, other.EndPoint);
            }

            return(closestPair);
        }
示例#2
0
        // Token: 0x06000140 RID: 320 RVA: 0x000098F0 File Offset: 0x00007AF0
        public ValueTuple <Vector3, Vector3> ClosestPointsBetween(Line3D other, bool mustBeOnSegments)
        {
            if (!this.IsParallelTo(other) || !mustBeOnSegments)
            {
                ValueTuple <Vector3, Vector3> valueTuple = this.ClosestPointsBetween(other);
                if (!mustBeOnSegments)
                {
                    return(valueTuple);
                }
                if ((valueTuple.Item1 - this.StartPoint).Length() <= this.GetLength() && (valueTuple.Item1 - this.EndPoint).Length() <= this.GetLength() && (valueTuple.Item2 - other.StartPoint).Length() <= other.GetLength() && (valueTuple.Item2 - other.EndPoint).Length() <= other.GetLength())
                {
                    return(valueTuple);
                }
            }
            Vector3 vector = other.ClosestPointTo(this.StartPoint, true);
            float   num    = (vector - this.StartPoint).Length();
            ValueTuple <Vector3, Vector3> result = new ValueTuple <Vector3, Vector3>(this.StartPoint, vector);
            float num2 = num;

            vector = other.ClosestPointTo(this.EndPoint, true);
            num    = (vector - this.EndPoint).Length();
            if (num < num2)
            {
                result = new ValueTuple <Vector3, Vector3>(this.EndPoint, vector);
                num2   = num;
            }
            vector = this.ClosestPointTo(other.StartPoint, true);
            num    = (vector - other.StartPoint).Length();
            if (num < num2)
            {
                result = new ValueTuple <Vector3, Vector3>(vector, other.StartPoint);
                num2   = num;
            }
            vector = this.ClosestPointTo(other.EndPoint, true);
            num    = (vector - other.EndPoint).Length();
            if (num < num2)
            {
                result = new ValueTuple <Vector3, Vector3>(vector, other.EndPoint);
            }
            return(result);
        }
示例#3
0
        // Token: 0x0600013F RID: 319 RVA: 0x00009818 File Offset: 0x00007A18
        public ValueTuple <Vector3, Vector3> ClosestPointsBetween(Line3D other)
        {
            if (this.IsParallelTo(other))
            {
                return(new ValueTuple <Vector3, Vector3>(this.StartPoint, other.ClosestPointTo(this.StartPoint, false)));
            }
            Vector3 direction  = this.GetDirection();
            Vector3 direction2 = other.GetDirection();
            Vector3 right      = this.StartPoint - other.StartPoint;
            float   num        = direction.Dot(direction);
            float   num2       = direction.Dot(direction2);
            float   num3       = direction2.Dot(direction2);
            float   num4       = direction.Dot(right);
            float   num5       = direction2.Dot(right);
            float   num6       = (num2 * num5 - num3 * num4) / (num * num3 - num2 * num2);
            float   num7       = (num * num5 - num2 * num4) / (num * num3 - num2 * num2);

            return(new ValueTuple <Vector3, Vector3>(this.StartPoint + num6 * direction, other.StartPoint + num7 * direction2));
        }