#On the name of ALLAH and may the blessing and peace of Allah #be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam. #Author : Fouad Teniou #Date : 06/05/10 #version :2.6 """ Sphere class represents a geometric sphere and a completing_the_squares function is used for the purpose, while an utility _checksign function is used to check the sign of all the coefficients and return an empty string for a positive number and a minus character for a negative number. A string representation function for the three different outcome possibilities is used to print the solution of the sphere equation. """ from math import sqrt class Sphere(object): """ class that represents a geometric Sphere """ def __init__(self,coef_A = 0,coef_B = 0, coef_C = 0, coef_D= 0, coef_E = 0, coef_F = 0, coef_G = 0): """ Sphere Construction takes coef_A,coef_B,coef_C,coef_D,coef_E,coef_F,coef_G constants """ self._A = coef_A self._B = coef_B self._C = coef_C self._D = coef_D self._E = coef_E self._F = coef_F self._G = coef_G self._a = self._checkSign(self._D) self._b = self._checkSign(self._E) self._c = self._checkSign(self._F) self._d = pow((self._D/2.0)/self._A,2) self._e = pow((self._E/2.0)/self._B,2) self._f = pow((self._F/2.0)/self._C,2) self._g = chr(253) self._h = (-self._G/self._A + self._d + self._e + self._f) def _checkSign(self,value): """ Utility method to check the values' sign and return a sign string""" if value >= 0: return "+" else : return "" def completing_the_squares(self): """ completing the squares function """ c_squares = "(x%s %s%sx + %s) + (y%s %s%sy + %s) + (z%s %s%sz + %s) = %s" % \ (self._g,self._a,self._D/self._A,self._d, self._g,self._b,self._E/self._B,self._e, self._g,self._c,self._F/self._C,self._f,self._h) return c_squares def __str__(self): """ String representation of a sphere """ print ("\n(x%s%s)%s + (y%s%s)%s + (z%s%s)%s = %s") % \ (self._a,(self._D/2.0)/self._A,self._g,self._b,(self._E/2.0)/self._B, self._g,self._c,(self._F/2.0)/self._C,self._g,self._h) if self._h > 0: return "\n