Ignore:
Timestamp:
08/23/07 10:57:20 (6 years ago)
Author:
Robert Bradshaw <robertwb@…>
Branch:
default
Message:

start 3d stuff, fix tabs/spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/groups/perm_gps/cubegroup.py

    r5644 r5894  
    3838    -      "       (2007-06): added plotting functions 
    3939    -      "       (2007-08): colors corrected, "solve" rewritten, and typos fixed. 
     40    - Robert Bradshaw (2006-08): RubiksCube object.  
    4041     
    4142REFERENCES: 
     
    5859import random 
    5960 
     61from sage.structure.sage_object import SageObject 
    6062import sage.structure.element as element 
    6163import sage.groups.group as group 
     
    7577sin = Function_sin() 
    7678cos = Function_cos() 
    77 pi = 3.14159265 
     79pi = RDF.pi() 
     80 
     81from sage.plot.graphics3d import * 
    7882 
    7983####################### predefined colors ################## 
     
    562566 
    563567 
     568 
     569 
    564570####################### end of "internal" utility plot functions  ################# 
    565571 
     
    610616         
    611617    def __str__(self): 
    612         return "The Rubik's cube group with genrators R,L,F,B,U,D in SymmetricGroup(48)." 
     618        return "The Rubik's cube group with genrators R,L,F,B,U,D in SymmetricGroup(48)." 
    613619         
    614620    def __repr__(self): 
    615         return "The PermutationGroup of all legal moves of the Rubik's cube." 
     621        return "The PermutationGroup of all legal moves of the Rubik's cube." 
    616622         
    617623    def __call__(self,other): 
     
    632638    def B(self): 
    633639        G = self.group() 
    634         g = G(self.gens()[0])     
     640        g = G(self.gens()[0])     
    635641        return g 
    636642             
    637643    def D(self): 
    638         G = self.group() 
    639         g = G(self.gens()[1])     
     644        G = self.group() 
     645        g = G(self.gens()[1])     
    640646        return g 
    641647 
    642648    def F(self): 
    643649        G = self.group() 
    644         g = G(self.gens()[2])     
     650        g = G(self.gens()[2])     
    645651        return g 
    646652             
    647653    def L(self): 
    648654        G = self.group() 
    649         g = G(self.gens()[3])     
     655        g = G(self.gens()[3])     
    650656        return g 
    651657 
    652658    def R(self): 
    653659        G = self.group() 
    654         g = G(self.gens()[4])     
     660        g = G(self.gens()[4])     
    655661        return g 
    656662             
    657663    def U(self): 
    658664        G = self.group() 
    659         g = G(self.gens()[5])     
     665        g = G(self.gens()[5])     
    660666        return g 
    661667             
     
    703709        r""" 
    704710        Returns the group element and the reordered list of facets, as moved by  
    705         the list mv (read left-to-right)  
    706          
    707         INPUT: mv is a string of the form X^a*Y^b*...",  
    708                where X, Y, ... are in {R,L,F,B,U,D} 
    709                and a,b, ... are integers. 
    710                 
    711         EXAMPLES: 
    712             sage: rubik = CubeGroup() 
    713             sage: rubik.move("")[0] 
    714             () 
    715             sage: rubik.move("R")[0] 
    716             (3,38,43,19)(5,36,45,21)(8,33,48,24)(25,27,32,30)(26,29,31,28) 
    717             sage: rubik.R() 
    718             (25,27,32,30)(26,29,31,28)(3,38,43,19)(5,36,45,21)(8,33,48,24) 
    719  
    720         """ 
    721         m = mv.split("*") 
    722         M = [x.split("^") for x in m] 
    723         #print M 
    724         n = len(M) 
    725         e = 0 
    726         G = self.group() 
    727         R,L,F,B,U,D = G.gens() 
    728         g = G(1) 
    729         fcts = self.facets() 
    730         for i in range(n): 
    731             if len(M[i])==1: 
    732                 M[i] = [M[i][0],"1"] 
    733         #print M 
    734         for i in range(n): 
    735             x = M[i][0] 
    736             if x == "R":   h = self.R() 
    737             elif x == "L": h = self.L() 
    738             elif x == "U": h = self.U() 
    739             elif x == "D": h = self.D() 
    740             elif x == "F": h = self.F() 
    741             elif x == "B": h = self.B() 
    742             else: h = G(1) 
    743             e = M[i][1] 
    744             if e=="1": g = g*h 
    745             if e=="2": g = g*h*h 
    746             if e=="3": g = g*h*h*h 
    747             if e=="(-1)": g = g*h*h*h 
    748         pos = [g(i) for i in fcts] 
    749         return [g,pos] 
     711        the list mv (read left-to-right)  
     712         
     713        INPUT: mv is a string of the form X^a*Y^b*...",  
     714               where X, Y, ... are in {R,L,F,B,U,D} 
     715               and a,b, ... are integers. 
     716                
     717        EXAMPLES: 
     718                sage: rubik = CubeGroup() 
     719            sage: rubik.move("")[0] 
     720            () 
     721            sage: rubik.move("R")[0] 
     722            (3,38,43,19)(5,36,45,21)(8,33,48,24)(25,27,32,30)(26,29,31,28) 
     723            sage: rubik.R() 
     724            (25,27,32,30)(26,29,31,28)(3,38,43,19)(5,36,45,21)(8,33,48,24) 
     725 
     726        """ 
     727        m = mv.split("*") 
     728        M = [x.split("^") for x in m] 
     729        #print M 
     730        n = len(M) 
     731            e = 0 
     732        G = self.group() 
     733        R,L,F,B,U,D = G.gens() 
     734        g = G(1) 
     735        fcts = self.facets() 
     736        for i in range(n): 
     737            if len(M[i])==1: 
     738                M[i] = [M[i][0],"1"] 
     739        #print M 
     740        for i in range(n): 
     741            x = M[i][0] 
     742                if x == "R":   h = self.R() 
     743            elif x == "L": h = self.L() 
     744            elif x == "U": h = self.U() 
     745            elif x == "D": h = self.D() 
     746            elif x == "F": h = self.F() 
     747            elif x == "B": h = self.B() 
     748            else: h = G(1) 
     749            e = M[i][1] 
     750            if e=="1": g = g*h 
     751            if e=="2": g = g*h*h 
     752            if e=="3": g = g*h*h*h 
     753                if e=="(-1)": g = g*h*h*h 
     754        pos = [g(i) for i in fcts] 
     755        return [g,pos] 
    750756         
    751757    def display2d(self,mv): 
     
    969975        return P 
    970976    return P 
     977 
     978 
     979 
     980########################################################## 
     981#              3d object generation 
     982########################################################## 
     983 
     984class RubiksCube(SageObject): 
     985     
     986    def __init__(self, facets=None, colors=[green, blue, yellow, white, orange, lpurple]): 
     987        self.colors = colors 
     988        self.facets =  
     989 
Note: See TracChangeset for help on using the changeset viewer.