Пример #1
0
        TestLineRayResult Intersect(Line line, Ray ray)
        {
            FindLineLine.FindLineLineResult llResult = FindLineLine.Intersect(line, new Line(ray.Origin, ray.Direction));

            if (llResult.NumIntersections == 1)
            {
                // Test whether the line-line intersection is on the ray.
                if (llResult.Line1Parameter >= 0)
                {
                    return(new TestLineRayResult(true, 1));
                }
                else
                {
                    return(new TestLineRayResult(false, 0));
                }
            }
            else
            {
                return(new TestLineRayResult(llResult.Intersect, llResult.NumIntersections));
            }
        }
Пример #2
0
        public static FindLineRayResult Intersect(Line line, Ray ray)
        {
            FindLineRayResult result = new FindLineRayResult();
            var llResult             = FindLineLine.Intersect(line, new Line(ray.Origin, ray.Direction));

            if (llResult.NumIntersections == 1)
            {
                // Test whether the line-line intersection is on the ray.
                if (llResult.Line1Parameter >= 0)
                {
                    result.Intersect        = true;
                    result.NumIntersections = 1;
                    result.LineParameter    = llResult.Line0Parameter;
                    result.RayParameter     = llResult.Line1Parameter;
                    result.Point            = llResult.Point;
                }
                else
                {
                    result.Intersect        = false;
                    result.NumIntersections = 0;
                    result.LineParameter    = float.NaN;
                    result.RayParameter     = float.NaN;
                }
            }
            else if (llResult.NumIntersections == int.MaxValue)
            {
                result.Intersect        = true;
                result.NumIntersections = int.MaxValue;
                result.LineParameter    = float.PositiveInfinity;
                result.RayParameter     = float.PositiveInfinity;
            }
            else
            {
                result.Intersect        = false;
                result.NumIntersections = 0;
                result.LineParameter    = float.NaN;
                result.RayParameter     = float.NaN;
            }
            return(result);
        }