/// <summary> /// Writes the given <see cref="Spherei"/> to an <see cref="Ibasa.IO.BinaryWriter">. /// </summary> public static void Write(this Ibasa.IO.BinaryWriter writer, Spherei sphere) { writer.Write(sphere.X); writer.Write(sphere.Y); writer.Write(sphere.Z); writer.Write(sphere.Radius); }
/// <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, Spherei 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))); }
public static bool Contains(Spherei sphere, Point3i point) { return(Vector.AbsoluteSquared(sphere.Center - point) <= sphere.Radius * sphere.Radius); }
/// <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(Spherei left, Spherei right) { return(left == right); }