コード例 #1
0
ファイル: Line3.cs プロジェクト: polytronicgr/Axiverse
        public static bool TryFindClosestPoint(
            Line3 former, Line3 latter, out Vector3 formerPoint, out Vector3 latterPoint)
        {
            Vector3 cross  = Vector3.Cross(former.Direction, latter.Direction);
            float   length = cross.Length();

            if (length == 0)
            {
                formerPoint = Vector3.Zero;
                latterPoint = Vector3.Zero;
                return(false);
            }

            Plane3 formerPlane = Plane3.FromPointTangents(former.Origin, cross, former.Direction);
            Plane3 latterPlane = Plane3.FromPointTangents(latter.Origin, cross, latter.Direction);

            var intersectsFormer = latterPlane.Intersect(former, out formerPoint);
            var intersectsLatter = formerPlane.Intersect(latter, out latterPoint);

            // Should always be true.
            return(intersectsFormer && intersectsLatter);
        }