why cannot print non integer epicycloid in command line?
Question: I want to create a program to print epicycloid:

    
    
    import math
    import sys
    WIDTH=30
    R=10.0
    N=3.0
    DELTA=0.01
    pixels=[[0 for y in range(WIDTH)] for x in range(WIDTH)]
    for f in range(0,(int)(2*math.pi/DELTA)):
        pixels[(int)(R*math.sin(f*DELTA)-R*math.sin((N+1)*f*DELTA)/(N+1)+WIDTH/2)][(int)(R*math.cos(f*DELTA)-R*math.cos((N+1)*f*DELTA)/(N+1)+WIDTH/2)]=1
    
    for row in pixels:
        for cell in row:
            sys.stdout.write('[]' if cell==1 else '  ')
        sys.stdout.write('\n')
    

and test with N=3,7,and 3.5, it seems work when N=3 and 7:

N=3

    
    
                          [][][][][][][][]                  
                        [][]            [][][]              
                      [][]                  [][]            
                      []                      [][]          
              [][][][][]                        []          
          [][]      [][]                        []          
        [][]                                    [][]        
      [][]                                        []        
      []                                        [][]        
    [][]                                        []          
    []                                          []          
    []                                      [][]            
    []                                      [][]            
    []                                          []          
    [][]                                        []          
      []                                        [][]        
      [][]                                        []        
        [][]                                    [][]        
          [][][]    [][]                        []          
              [][][][][]                        []          
                      []                      [][]          
                      [][]                  [][]            
                        [][]              [][]              
                          [][][][][][][][]                  
    

N=7

    
    
                              [][][]                        
                          [][][]  [][][]                    
                [][][][][][]          [][]                  
              [][]      [][]            []                  
            [][]                        [][][]              
            []                          []  [][][]          
            []                                  [][]        
            []                                    []        
        [][][][]                                  []        
        []                                        []        
      [][]                                        []        
      []                                      [][][]        
      []                                      [][]          
      [][]                                        []        
        []                                        []        
          [][][]                                  []        
            []                                    []        
            []                                  [][]        
            []                          []  [][][]          
            [][]                        [][][]              
              [][]      [][]            []                  
                [][][][][][]          [][]                  
                          [][][]  [][][]                    
                              [][][]                        
    

but when N=3.5 the shape is not I expected (star like something):

    
    
                        [][][]                              
                    [][][]    [][][]                        
                [][]              [][]                      
                []                  [][]                    
              []                      []                    
              []                      [][]                  
            [][]                      [][][][][]            
            [][]                              [][][]        
              []                                  []        
            [][]                                    []      
        [][][]                                      []      
        []                                          [][]    
      [][]                                            []    
      []                                    [][][]          
      []                                        []          
      []                                        [][]        
      []                                          []        
      []                                          []        
      [][]                                        []        
        [][]                                    []          
          [][]            []                    []          
            [][][]    [][][]                  []            
                [][][][]  [][]              [][]            
                            [][][]    [][][]                
                                  [][][]                    
    

I checked the formula so long time,also my parameter used float until convert
the result to pixel position,but still not found what is wrong,can anyone
help?

(I want to solve it using python,but I found the original java version also
has similar problem,I even don't know which type of problem (e.g.:wrong
formula,number type casting,or wrong code) causes it)


Answer: When you have a fractional `N=p/q`, you need to go to `2*q*math.pi`. Let's
explore what I mean.

For `N=3.5`,

    
    
    parametric plot (sin(t)-sin(4.5t)/4.5 , cos(t)-cos(4.5t)/4.5) for t in [0,2pi]
    

in [Wolfram
Alpha](http://www.wolframalpha.com/input/?i=parametric+plot+\(sin\(t\)-sin\(4.5t\)%2F4.5+,+cos\(t\)-cos\(4.5t\)%2F4.5\)+for+t+in+%5B0,2pi%5D)
yields:

[![N=3.5, 0 to
2pi](http://i.stack.imgur.com/G5ZEd.png)](http://i.stack.imgur.com/G5ZEd.png)

which is similar to your output.

On the other hand, an [upper
limit](http://www.wolframalpha.com/input/?i=parametric+plot+\(sin\(t\)-sin\(4.5t\)%2F4.5+,+cos\(t\)-cos\(4.5t\)%2F4.5\)+for+t+in+%5B0,4pi%5D)
of [0,4pi] gets the other half:

[![N=3.5, 0 to
4pi](http://i.stack.imgur.com/Rm79e.png)](http://i.stack.imgur.com/Rm79e.png)

Finally, if N is 1/7, we [have to
use](http://www.wolframalpha.com/input/?i=parametric+plot+\(sin\(t\)-7sin\(8t%2F7\)%2F8+,+cos\(t\)-7cos\(8t%2F7\)%2F8\)+for+t+in+%5B0,14pi%5D)
[0,14pi] to get:

[![N=1/7, 0 to
14pi](http://i.stack.imgur.com/TgNMv.png)](http://i.stack.imgur.com/TgNMv.png)

