On Sat, Apr 10, 2010 at 4:41 PM, kirby urner <kirby.ur...@gmail.com> wrote: > Below is current source for ch.py, a module for exploring volume > relationships starting with a "ground state" (a default) known as the > concentric hierarchy of polyhedra.
OK, a couple replies to this one: (a) I found the bug: I'd neglected to subclass 'object' as my root object, so was not getting new-style classes, just classic classes -- we still have that distinction in 2.6. (b) I made numerous enhancements for this new improved deluxe edition, appended herewith: """ Radical Math, Portland, Oregon (April, 2010) A reading and Python module (GPL, 4Dsolutions.net) """ from math import sqrt as radical phi = (1 + radical(5))/2 class Poly( object): def __init__(self, edge = 1, edge_name = "edge", volume = 1, greekname = "Tetrahedron", platonic = True, dual = "Tetrahedron"): self.edge = edge self.edge_name = edge_name self.volume = volume self.greekname = greekname self.platonic = platonic self.dual = dual def scale(self, scalefactor): edge = self.edge * scalefactor # edge unbound to self volume = self.volume * pow(scalefactor, 3) # likewise volume # print("DEBUG: a star is born: a new %s" % self.__class__.__name__) return self.__class__(edge = edge, edge_name = self.edge_name, volume = volume, greekname = self.greekname) __mul__ = __rmul__ = scale # e.g. tetra = tetra * 3 def __repr__(self): return "Polyhedron of type %s (vol: %s)" % (self.greekname, self.volume) class Tetra( Poly ): pass class Cube( Poly ): def __init__(self, edge = 1, edge_name = "any face diagonal", volume = 3, greekname = "Cube", platonic=True, dual="Octahedron"): super(Cube, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) class Octa( Poly ): def __init__(self, edge = 1, edge_name = "any edge", volume = 4, greekname = "Octahedron", platonic=True, dual="Cube"): super(Octa, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) class R_Dodeca( Poly ): def __init__(self, edge = 1, edge_name = "any long face diagonal", volume = 6, greekname = "Rhombic Dodecahedron", platonic=False, dual="Cuboctahedron"): super(R_Dodeca, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) class R_Triac( Poly ): def __init__(self, edge = radical(2)/2, edge_name = "any long face diagonal", volume = 7.5, greekname = "Rhombic Triacontahedron", platonic=False, dual="Icosidodecahedron"): super(R_Triac, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) class Icosa ( Poly ): def __init__(self, edge = 1.0, edge_name = "any edge", volume = 5 * phi**2 * radical(2), greekname = "Icosahedron", platonic=True, dual="Pentagonal Dodecahedron"): super(Icosa, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) class P_Dodeca ( Poly ): def __init__(self, edge = 1/phi, edge_name = "any edge", volume = (phi**2 + 1) * 3 * radical(2), greekname = "Pentagonal Dodecahedron", platonic=True, dual="Icosahedron"): super(P_Dodeca, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) class Cubocta ( Poly ): def __init__(self, edge = 1, edge_name = "any edge", volume = 20, greekname = "Cuboctahedron", platonic=False, dual = "Rhombic Dodecahedron"): super(Cubocta, self).__init__(*(edge, edge_name, volume, greekname, platonic, dual)) def test1(): c = Cube() print "First shape: %s" % c print "Dual: %s Platonic: %s" % (c.dual, c.platonic) d = P_Dodeca() print "Second shape: %s" % d print "Dual: %s Platonic: %s" % (d.dual, d.platonic) def test2(): print "\n\nVolumes Table\n=============" for shape in (Tetra(), Cube(), Octa(), R_Triac()*pow(2./3,1./3), R_Dodeca(), R_Triac(), P_Dodeca(), Icosa(), Cubocta()): poly = "{0} ({1} = {2:.4g})".format(shape.greekname, shape.edge_name, shape.edge) print "{0:<60}{1:>8.4g}".format(poly, shape.volume) def test3(): print "\n\nDuals Table\n==========" for shape in (Tetra(), Cube(), Octa(), R_Dodeca(), R_Triac(), P_Dodeca(), Icosa(), Cubocta()): print "{0:<30}{1}".format(shape.greekname+" *"[int(shape.platonic)], shape.dual) print "\n * = Platonic" if __name__ == "__main__": print """ <plot tone="whimsical / buckaneer" type="non-fiction"> Silicon Foresters, aided by committed allies from the USA and elsewhere, battled the tyranny of an over-specialized majority unwilling to share important heritage. Our hero, Medal of Freedom winner and premier architect of his age, had contributed some valuable pedagogical and andragogical assets, yet these were sequestered as Verboten Math by some conspiracy of know-it-alls, rumoredly with a HQS near Princeton (the better to work with ETS perhaps). 1879 Hall fought back brilliantly, bringing Wittgenstein (LW) to bear etc. Note: D. Coxeter aka "King of IS" was a student of LW's @ Cambridge, and later worked with our hero on various geometric discoveries. Dr. Arthur Loeb, a true Renaissance man, was a bridge to M.C. Escher. Legend: ETS = Educational Testing Service IS = 'Infinite Space' (from a recent title) 1879 Hall = served Princeton U's philo & religion depts in 1970s, has since been enlarged. </plot> """ # test1() test2() test3() _______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig