Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168692
Image: ubuntu2004
var('x y') # Implicit plot of a circle var('x y') circle = implicit_plot(x^2+y^2==1 ,(x, -1, 1),(y, -1, 1))
# Draw a hyperbolic line segment between two points (u_1,u_2) and (v_1,v_2) def hyperbolic_segment((u_1,u_2),(v_1,v_2)): dx = u_1-v_1 dy = u_2-v_2 cross_term = u_1*v_2-u_2*v_1 if bool(cross_term == 0): return 2*dy*x - 2*dx*y == 0 else: return x^2+y^2+ ( 2*x*dy/cross_term ) - ( 2*y*dx/cross_term ) + 1 == 0
def draw_segments(P1,P2,P3): plots = [] #Draw hyperbolic line segments for first in [P1,P2,P3]: for second in [P1,P2,P3]: if first != second: plot = implicit_plot(hyperbolic_segment(first,second),(x,-5,5),(y,-5,5),linestyle='dotted') plots.append(plot) for p in [P1,P2,P3]: plots.append(point(p,rgbcolor=(1,0,0))) return plots
@interact def _(angle_1=slider(0,2*pi,1/100*pi,0), angle_2=slider(0,2*pi,1/100*pi,pi/2), angle_3=slider(0,2*pi,1/100*pi,pi/3), zoom=(1..10)): # Angle -> Rectangular Coordinates P1 = ( cos(angle_1) , sin(angle_1) ) P2 = ( cos(angle_2) , sin(angle_2) ) P3 = ( cos(angle_3) , sin(angle_3) ) plots = draw_segments(P1,P2,P3) (circle + sum(plots)).show(aspect_ratio=1,frame=false,xmin=-zoom,xmax=zoom,ymin=-zoom,ymax=zoom)
def half(i): a,b = i return ((a,(a+b)/2) , ((a+b)/2,b)) plots = [] def split_recursively(interval,depth=0): if depth == 6: return half(interval) j, k = half(interval) js, je = j ks, ke = k pt1 = ( cos(js) , sin(js) ) pt2 = ( cos(je) , sin(je) ) pt3 = ( cos(ks) , sin(ks) ) pt4 = ( cos(ke) , sin(ke) ) f = 1.0 plot1 = implicit_plot(hyperbolic_segment(pt1,pt2),(x,-f,f),(y,-f,f),linestyle='solid') plot2 = implicit_plot(hyperbolic_segment(pt3,pt4),(x,-f,f),(y,-f,f),linestyle='solid') plots.extend([plot1,plot2]) split_recursively(j,depth+1) split_recursively(k,depth+1) split_recursively((0,2*pi)) #print plots zoom = 1 (circle + sum(plots)).show(aspect_ratio=1,frame=false,xmin=-zoom,xmax=zoom,ymin=-zoom,ymax=zoom)