CoCalc Public FileslogSpiralInteract.sagewsOpen with one click!
Author: Pat Browne
Views : 42
Description: GraphicsIssueslogSpiral
Compute Environment: Ubuntu 18.04 (Deprecated)
class logSpiral: def __init__(self): self.size = 0 self.points = [] self.pointsR = [] self.g = Graphics() def normal(self,xyPoints,xyI): var('x') aPoint = xyPoints[0] bPoint = xyPoints[1] #deltay = 0 if bPoint[1] == aPoint[1]: return 0 #deltax = 0 if bPoint[0] == aPoint[0]: return 1e6 m = -(bPoint[0] - aPoint[0])/ (bPoint[1] - aPoint[1]) b = xyI[1] - m*xyI[0] return N(m)*x + b def eqnLine(self,aPoint,bPoint): var('x') yb = bPoint[1] ya = aPoint[1] xb = bPoint[0] xa = aPoint[0] m = (yb - ya) / (xb -xa) return m*(x - xa) + ya def doSpiral(self,n,c): #print "doSpiral received n, c",n,c self.points= [[[0.0,0.0],[ N(7*cos(pi*k/6.0)), N(6*sin(pi*k/6.0))]] for k in range(n)] self.pointsR = [[[0.0,0.0],[ N(7*cos(pi*k/6.0)), N(6*sin(pi*k/6.0))]] for k in range(n,0,-1)] spiral = self.pointsR if c == True else self.points #print spiral px = spiral[0][1][0]/5.0 py = spiral[0][1][1]/5.0 x,y = var('x','y') self.g = Graphics() lprev = None ptIx = None #self.g = polar_plot([ r for r in range(1,8)],(x,0,2*pi)) #debug issue 1 fixed - keep one color for all circles by not using polar plot for r in range(1,8): self.g += circle((0,0),r) for i in range(n): lxy = spiral[i] #print "lxy",lxy self.g += line(lxy) if lprev <> None: slopeExp = self.eqnLine(lxy[0],lxy[1]) eqn = y - slopeExp #print "eqn {}".format(eqn) if eqn == y: #print "lxy and lprev for horizontal{} {}".format(lxy,lprev[1]) norm = y - self.eqnLine(lprev[1],lxy[1]) #print "adjusting norm {}".format(norm) else: deltaY = lprev[1][1] - lprev[0][1] if deltaY == 0: ptIx = px yy = self.eqnLine(lxy[0],lxy[1]) ptIy = yy.subs(x=px) else: norm = y - self.normal([[0.0,0.0],[px,py]],[px,py]) #print "eqn",eqn #print "norm",norm pointI = solve([eqn,norm],x,y,solution_dict=True) ptIx = N(pointI[0][x]) ptIy = N(pointI[0][y]) #print "debug point of intersection",N(ptIx),N(ptIy) gn = line([[px,py],[ptIx,ptIy]],color='red') self.g += gn lprev = lxy if ptIx <> None: px = ptIx py = ptIy self.g.show() #return self.g def magnitude(self): #sage doesn't like classes using keywords size or length for methods!!! return self.size def remove(self,n): self.g = None logspiral = logSpiral() @interact def logSpiralInteract(n = slider(1,100,1,12, label="Radials"),c = checkbox(False,"Reverse")): logspiral.doSpiral(n,c)
Interact: please open in CoCalc
show(graphs.PetersenGraph().plot3d(), frame=False) parametric_plot([cos(x) + 2*cos(x/4), sin(x) - 2*sin(x/4)], (x,0,8*pi), color='green', thickness=3, fill = True)
3D rendering not yet implemented
/ext/sage/sage-8.0/local/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
CC continued_fraction(e)