private static int[] GetFieldSphere(Point3D point, double radius, FluidField3D field) { // Get the box that contains the return circle var center = GetFieldPoint_XYZ(point, field); var min = GetFieldPoint_XYZ(new Point3D(point.X - radius, point.Y - radius, point.Z - radius), field); var max = GetFieldPoint_XYZ(new Point3D(point.X + radius, point.Y + radius, point.Z + radius), field); // Get points that are inside the circle List<int> retVal = new List<int>(); double maxDistance = radius * field.Size; double maxDistanceSquared = maxDistance * maxDistance; for (int x = min.Item1; x <= max.Item1; x++) { for (int y = min.Item2; y <= max.Item2; y++) { for (int z = min.Item3; z <= max.Item3; z++) { double dx = x - center.Item1; double dy = y - center.Item2; double dz = z - center.Item3; double distanceSquared = (dx * dx) + (dy * dy) + (dz * dz); if (distanceSquared <= maxDistanceSquared) { retVal.Add(field.Get1DIndex(x, y, z)); } } } } // Exit Function return retVal.ToArray(); }