示例#1
0
        public double Intersect(Sphere3D sphere)
        {
            var l    = Direction.Normalized;
            var ldpc = l.DotProduct(sphere.Position);
            var d    = ldpc.Sqr() - l.Square * (sphere.Position.Square - sphere.RadiusSquare);

            if (d < 0)
            {
                return(double.PositiveInfinity);
            }
            d = Math.Sqrt(d);

            var result = ldpc - d;

            if (result >= 0)
            {
                return(result);
            }
            result = ldpc + d;
            if (result >= 0)
            {
                return(result);
            }
            return(double.PositiveInfinity);
        }
示例#2
0
 public bool IntersectsBall(Sphere3D ball)
 {
     return((this.Position - ball.Position).Square <= MathEx.Sqr(Radius + ball.Radius));
 }