def main4(): print("MAIN 4:") zeta = CDF(exp(Integer(2) * pi * I / Integer(5))) print(zeta) v = [legendre_symbol(n, Integer(5)) * zeta**(Integer(2) * n) for n in range(Integer(1), Integer(5))] S = sum([point(tuple(z), pointsize=Integer(100)) for z in v]) G = point(tuple(sum(v)), pointsize=Integer(100), rgbcolor='red') (S + G).save(filename="gauss_sum.png") print()
def healpix_diagram(a=1, e=0, shade_polar_region=True): r""" Return a Sage Graphics object diagramming the HEALPix projection boundary and polar triangles for the ellipsoid with major radius `a` and eccentricity `e`. Inessential graphics method. Requires Sage graphics methods. """ from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer # Make Sage types compatible with Numpy. RealNumber = float Integer = int R = auth_rad(a, e) g = Graphics() color = 'black' # Boundary color. shade_color = 'blue' # Polar triangles color. dl = array((R*pi/2,0)) lu = [(-R*pi, R*pi/4),(-R*3*pi/4, R*pi/2)] ld = [(-R*3*pi/4, R*pi/2),(-R*pi/2, R*pi/4)] g += line2d([(-R*pi, -R*pi/4),(-R*pi, R*pi/4)], color=color) g += line2d([(R*pi, R*pi/4),(R*pi, -R*pi/4)], linestyle = '--', color=color) for k in range(4): g += line2d([array(p) + k*dl for p in lu], color=color) g += line2d([array(p) + k*dl for p in ld], linestyle = '--', color=color) g += line2d([array(p) + array((k*R*pi/2 - R*pi/4, -R*3*pi/4)) for p in ld], color=color) g += line2d([array(p) + array((k*R*pi/2 + R*pi/4, -R*3*pi/4)) for p in lu], linestyle = '--', color=color) pn = array((-R*3*pi/4, R*pi/2)) ps = array((-R*3*pi/4, -R*pi/2)) g += point([pn + k*dl for k in range(4)] + [ps + k*dl for k in range(4)], size=20, color=color) g += point([pn + k*dl for k in range(1, 4)] + [ps + k*dl for k in range(1, 4)], color='white', size=10, zorder=3) npp = [(-R*pi, R*pi/4), (-R*3*pi/4, R*pi/2), (-R*pi/2, R*pi/4)] spp = [(-R*pi, -R*pi/4), (-R*3*pi/4, -R*pi/2), (-R*pi/2, -R*pi/4)] if shade_polar_region: for k in range(4): g += polygon([array(p) + k*dl for p in npp], alpha=0.1, color=shade_color) g += text(str(k), array((-R*3*pi/4, R*5*pi/16)) + k*dl, color='red', fontsize=20) g += polygon([array(p) + k*dl for p in spp], alpha=0.1, color=shade_color) g += text(str(k), array((-R*3*pi/4, -R*5*pi/16)) + k*dl, color='red', fontsize=20) return g
def eqn_list_to_curve_plot(L, rat_pts): xpoly_rng = PolynomialRing(QQ, 'x') poly_tup = [xpoly_rng(tup) for tup in L] f = poly_tup[0] h = poly_tup[1] g = f + h**2 / 4 if len(g.real_roots()) == 0 and g(0) < 0: return text(r"$X(\mathbb{R})=\emptyset$", (1, 1), fontsize=50) X0 = [real(z[0]) for z in g.base_extend(CC).roots() ] + [real(z[0]) for z in g.derivative().base_extend(CC).roots()] a, b = inflate_interval(min(X0), max(X0), 1.5) groots = [a] + g.real_roots() + [b] if b - a < 1e-7: a = -3 b = 3 groots = [a, b] ngints = len(groots) - 1 plotzones = [] npts = 100 for j in range(ngints): c = groots[j] d = groots[j + 1] if g((c + d) / 2) < 0: continue (c, d) = inflate_interval(c, d, 1.1) s = (d - c) / npts u = c yvals = [] for i in range(npts + 1): v = g(u) if v > 0: v = sqrt(v) w = -h(u) / 2 yvals.append(w + v) yvals.append(w - v) u += s (m, M) = inflate_interval(min(yvals), max(yvals), 1.2) plotzones.append((c, d, m, M)) x = var('x') y = var('y') plot = sum( implicit_plot(y**2 + y * h(x) - f(x), (x, R[0], R[1]), (y, R[2], R[3]), aspect_ratio='automatic', plot_points=500, zorder=1) for R in plotzones) xmin = min([R[0] for R in plotzones]) xmax = max([R[1] for R in plotzones]) ymin = min([R[2] for R in plotzones]) ymax = max([R[3] for R in plotzones]) for P in rat_pts: (x, y, z) = P z = ZZ(z) if z: # Do not attempt to plot points at infinity x = ZZ(x) / z y = ZZ(y) / z**3 if x >= xmin and x <= xmax and y >= ymin and y <= ymax: plot += point((x, y), color='red', size=40, zorder=2) return plot
def main6(): c = continued_fraction([Integer(1)] * (8)) v = [(i, c.p(i) / c.q(i)) for i in range(c.length())] P = point(v, rgbcolor=(0, 0, 1), pointsize=40) L = line(v, rgbcolor=(0.5, 0.5, 0.5)) L2 = line([(Integer(0), c.value()), (c.length() - Integer(1), c.value())], thickness=0.5, rgbcolor=(0.7, 0, 0)) (L + L2 + P).save(filename="continued_fraction.png") print("Graph is saved as continued_fraction.png")
def eqn_list_to_curve_plot(L,rat_pts): xpoly_rng = PolynomialRing(QQ,'x') poly_tup = [xpoly_rng(tup) for tup in L] f = poly_tup[0] h = poly_tup[1] g = f+h**2/4 if len(g.real_roots())==0 and g(0)<0: return text("$X(\mathbb{R})=\emptyset$",(1,1),fontsize=50) X0 = [real(z[0]) for z in g.base_extend(CC).roots()]+[real(z[0]) for z in g.derivative().base_extend(CC).roots()] a,b = inflate_interval(min(X0),max(X0),1.5) groots = [a]+g.real_roots()+[b] if b-a<1e-7: a=-3 b=3 groots=[a,b] ngints = len(groots)-1 plotzones = [] npts = 100 for j in range(ngints): c = groots[j] d = groots[j+1] if g((c+d)/2)<0: continue (c,d) = inflate_interval(c,d,1.1) s = (d-c)/npts u = c yvals = [] for i in range(npts+1): v = g(u) if v>0: v = sqrt(v) w = -h(u)/2 yvals.append(w+v) yvals.append(w-v) u += s (m,M) = inflate_interval(min(yvals),max(yvals),1.2) plotzones.append((c,d,m,M)) x = var('x') y = var('y') plot=sum(implicit_plot(y**2 + y*h(x) - f(x), (x,R[0],R[1]),(y,R[2],R[3]), aspect_ratio='automatic', plot_points=500, zorder=1) for R in plotzones) xmin=min([R[0] for R in plotzones]) xmax=max([R[1] for R in plotzones]) ymin=min([R[2] for R in plotzones]) ymax=max([R[3] for R in plotzones]) for P in rat_pts: (x,y,z)=eval(P.replace(':',',')) z=ZZ(z) if z: # Do not attempt to plot points at infinity x=ZZ(x)/z y=ZZ(y)/z**3 if x >= xmin and x <= xmax and y >= ymin and y <= ymax: plot += point((x,y),color='red',size=40,zorder=2) return plot
def displayFlightTrajectoryInfo(self, flight, render=True, threed=False): """Display info and render trajectory.""" T0 = pd.to_datetime('2020-07-01T00') dt = pd.to_timedelta(int(flight.cycleTime), 'S') times = pd.date_range(start=T0, end=T0 + dt, freq='30S', tz='America/Detroit') print(' Flight Info') print('=' * 80) print('%d Second cycles, for %d cycles with %d left over' % (flight.cycleTime, (24 * 3600) / flight.cycleTime, (24 * 3600) % flight.cycleTime)) poses = flight.toPoses(times.to_series()) print('altitude min=%d mean=%d max=%d' % (poses.z.min(), poses.z.mean(), poses.z.max())) if render: if threed: show(flight._trajectory.render()) else: points = [ point( ( poses['x'][poses.index[i]], poses['y'][poses.index[i]], #poses['z'][poses.index[i]] ), color=hue(i / len(poses.index)), size=100) for i in range(len(poses.index)) ] points.extend([point((x, y)) for x, y, z in self._scene.users]) show(sum(points), aspect_ratio=1) print() print()
def graphical(ao): r""" Return a sage graphics representation of the given acyclic orientation. """ from sage.all import Graphics, point, line assert is_orientation(ao) n, ascents, descents = ao # compute heights height = [0]*n for _ in range(n): for (i, j) in ascents: height[j] = max(height[j], height[i]+1) for (i, j) in descents: height[i] = max(height[i], height[j]+1) # compute the extent of each interval left = range(n) right = range(n) for (i, j) in ascents: right[i] += .75 left[j] -= .75 for (i, j) in descents: right[i] += .75 left[j] -= .75 result = Graphics() # put in the ascents and descents for (i, j) in ascents: result += line([(i, height[i]), (j, height[j])], color='red', thickness=2) for (i, j) in descents: result += line([(i, height[i]), (j, height[j])], color='blue', thickness=2) # then put in the intervals for i in range(n): result += line([(left[i], height[i]), (right[i], height[i])], color='black', thickness=2) result += point([(i, height[i])], color='black', size=100) # reset some annoying options result.axes(False) result.set_aspect_ratio(1) return result
def plot_polygon(Delta, remove_points=[]): P = Delta.integral_points() AUT = polygon_symmetries(Delta) F = fundamental_domain(Delta, AUT) fundam = fundamental_points(F, AUT) plt = Delta.plot(fill="yellow", point=False, zorder=-10) plt += F.plot(fill=(1,0.9,0), point=False, zorder=-9) for pt in P: style = {'pointsize': 80, 'color': (0.4,0.5,1)} if pt in remove_points: style['color'] = (0.7,0,0) style['marker'] = "x" elif Delta.interior_contains(pt): if pt in fundam: style['color'] = (0.2,0.8,0) else: style['color'] = (0,1,0) plt += point(pt, **style) return plt
def rhealpix_diagram(a=1, e=0, north_square=0, south_square=0, shade_polar_region=True): r""" Return a Sage Graphics object diagramming the rHEALPix projection boundary and polar triangles for the ellipsoid with major radius `a` and eccentricity `e`. Inessential graphics method. Requires Sage graphics methods. """ from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer # Make Sage types compatible with Numpy. RealNumber = float Integer = int R = auth_rad(a, e) g = Graphics() color = 'black' # Boundary color. shade_color = 'blue' # Polar triangles color. north = north_square south = south_square south_sq = [(-R * pi + R * south * pi / 2, -R * pi / 4), (-R * pi + R * south * pi / 2, -R * 3 * pi / 4), (-R * pi + R * (south + 1) * pi / 2, -R * 3 * pi / 4), (-R * pi + R * (south + 1) * pi / 2, -R * pi / 4)] north_sq = [(-R * pi + R * north * pi / 2, R * pi / 4), (-R * pi + R * north * pi / 2, R * 3 * pi / 4), (-R * pi + R * (north + 1) * pi / 2, R * 3 * pi / 4), (-R * pi + R * (north + 1) * pi / 2, R * pi / 4)] # Outline. g += line2d(south_sq, linestyle='--', color=color) g += line2d(north_sq, linestyle='--', color=color) g += line2d([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)], linestyle='--', color=color) g += line2d([ north_sq[0], (-R * pi, R * pi / 4), (-R * pi, -R * pi / 4), south_sq[0] ], color=color) g += line2d([south_sq[3], (R * pi, -R * pi / 4)], color=color) g += line2d([north_sq[3], (R * pi, R * pi / 4)], color=color) g += point([south_sq[0], south_sq[3]], size=20, zorder=3, color=color) g += point([north_sq[0], north_sq[3]], size=20, zorder=3, color=color) g += point([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)], size=20, zorder=3, color=color) g += point([(R * pi, -R * pi / 4), (R * pi, R * pi / 4)], size=10, color='white', zorder=3) if shade_polar_region: # Shade. g += polygon(south_sq, alpha=0.1, color=shade_color) g += polygon(north_sq, alpha=0.1, color=shade_color) # Slice square into polar triangles. g += line2d([south_sq[0], south_sq[2]], color='lightgray') g += line2d([south_sq[1], south_sq[3]], color='lightgray') g += line2d([north_sq[0], north_sq[2]], color='lightgray') g += line2d([north_sq[1], north_sq[3]], color='lightgray') # Label polar triangles. sp = south_sq[0] + R * array((pi / 4, -pi / 4)) np = north_sq[0] + R * array((pi / 4, pi / 4)) shift = R * 3 * pi / 16 g += text(str(south), sp + array((0, shift)), color='red', fontsize=20) g += text(str((south + 1) % 4), sp + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((south + 2) % 4), sp + array((0, -shift)), color='red', rotation=180, fontsize=20) g += text(str((south + 3) % 4), sp + array((-shift, 0)), color='red', rotation=270, fontsize=20) g += text(str(north), np + array((0, -shift)), color='red', fontsize=20) g += text(str((north + 1) % 4), np + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((north + 2) % 4), np + array((0, shift)), color='red', rotation=180, fontsize=20) g += text(str((north + 3) % 4), np + array((-shift, 0)), color='red', rotation=270, fontsize=20) return g
def rhealpix_diagram(a=1, e=0, north_square=0, south_square=0, shade_polar_region=True): r""" Return a Sage Graphics object diagramming the rHEALPix projection boundary and polar triangles for the ellipsoid with major radius `a` and eccentricity `e`. Inessential graphics method. Requires Sage graphics methods. """ from sage.all import Graphics, line2d, point, polygon, text, RealNumber, Integer # Make Sage types compatible with Numpy. RealNumber = float Integer = int R = auth_rad(a, e) g = Graphics() color = 'black' # Boundary color. shade_color = 'blue' # Polar triangles color. north = north_square south = south_square south_sq = [(-R*pi + R*south*pi/2, -R*pi/4), (-R*pi + R*south*pi/2, -R*3*pi/4), (-R*pi + R*(south + 1)*pi/2, -R*3*pi/4), (-R*pi + R*(south + 1)*pi/2, -R*pi/4)] north_sq = [(-R*pi + R*north*pi/2, R*pi/4), (-R*pi + R*north*pi/2, R*3*pi/4), (-R*pi + R*(north + 1)*pi/2, R*3*pi/4), (-R*pi + R*(north + 1)*pi/2, R*pi/4)] # Outline. g += line2d(south_sq, linestyle = '--', color=color) g += line2d(north_sq, linestyle = '--', color=color) g += line2d([(R*pi, -R*pi/4), (R*pi, R*pi/4)], linestyle='--', color=color) g += line2d([north_sq[0], (-R*pi, R*pi/4), (-R*pi, -R*pi/4), south_sq[0]], color=color) g += line2d([south_sq[3], (R*pi, -R*pi/4)], color=color) g += line2d([north_sq[3],(R*pi, R*pi/4)], color=color) g += point([south_sq[0], south_sq[3]], size=20, zorder=3, color=color) g += point([north_sq[0], north_sq[3]], size=20, zorder=3, color=color) g += point([(R*pi, -R*pi/4), (R*pi, R*pi/4)], size=20, zorder=3, color=color) g += point([(R*pi, -R*pi/4), (R*pi, R*pi/4)], size=10, color='white', zorder=3) if shade_polar_region: # Shade. g += polygon(south_sq, alpha=0.1, color=shade_color) g += polygon(north_sq, alpha=0.1, color=shade_color) # Slice square into polar triangles. g += line2d([south_sq[0], south_sq[2]], color='lightgray') g += line2d([south_sq[1], south_sq[3]], color='lightgray') g += line2d([north_sq[0], north_sq[2]], color='lightgray') g += line2d([north_sq[1], north_sq[3]], color='lightgray') # Label polar triangles. sp = south_sq[0] + R*array((pi/4, -pi/4)) np = north_sq[0] + R*array((pi/4, pi/4)) shift = R*3*pi/16 g += text(str(south), sp + array((0, shift)), color='red', fontsize=20) g += text(str((south + 1) % 4), sp + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((south + 2) % 4), sp + array((0, -shift)), color='red', rotation=180, fontsize=20) g += text(str((south + 3) % 4), sp + array((-shift, 0)), color='red', rotation=270, fontsize=20) g += text(str(north), np + array((0, -shift)), color='red', fontsize=20) g += text(str((north + 1) % 4), np + array((shift, 0)), color='red', rotation=90, fontsize=20) g += text(str((north + 2) % 4), np + array((0, shift)), color='red', rotation=180, fontsize=20) g += text(str((north + 3) % 4), np + array((-shift, 0)), color='red', rotation=270, fontsize=20) return g
def render(self, **kwargs): """render our ground users.""" return sum([point(p, **kwargs) for p in self.users])