Ejemplo n.º 1
0
 /// <summary>
 /// Writes the given <see cref="Spherel"/> to an <see cref="Ibasa.IO.BinaryWriter">.
 /// </summary>
 public static void Write(this Ibasa.IO.BinaryWriter writer, Spherel sphere)
 {
     writer.Write(sphere.X);
     writer.Write(sphere.Y);
     writer.Write(sphere.Z);
     writer.Write(sphere.Radius);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether a ray intersects the specified sphere.
        /// </summary>
        /// <param name="ray">The ray which will be tested for intersection.</param>
        /// <param name="sphere">A sphere that will be tested for intersection.</param>
        /// <returns>Distance at which the ray intersects the sphere or null if there is no intersection.</returns>
        public static double?Intersects(Rayd ray, Spherel sphere)
        {
            var distance = sphere.Center - ray.Position;
            var pyth     = Vector.AbsoluteSquared(distance);
            var rr       = sphere.Radius * sphere.Radius;

            if (pyth <= rr)
            {
                return(0);
            }
            double dot = Vector.Dot(distance, ray.Direction);

            if (dot < 0)
            {
                return(null);
            }
            var temp = pyth - (dot * dot);

            if (temp > rr)
            {
                return(null);
            }
            return((double)(dot - Functions.Sqrt(rr - temp)));
        }
Ejemplo n.º 3
0
 public static bool Contains(Spherel sphere, Point3l point)
 {
     return(Vector.AbsoluteSquared(sphere.Center - point) <= sphere.Radius * sphere.Radius);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns a value that indicates whether two spherees are equal.
 /// </summary>
 /// <param name="left">The first sphere to compare.</param>
 /// <param name="right">The second sphere to compare.</param>
 /// <returns>true if the left and right are equal; otherwise, false.</returns>
 public static bool Equals(Spherel left, Spherel right)
 {
     return(left == right);
 }