p1_mrg_geometry

2890 days ago by LAC2011

x1 = 1 y1 = 2 x2 = -3 y2 = -5 p1 = (x1,y1) p2 = (x2,y2) l1 = line([p1,p2]) xAVG=(x1+x2)/2 yAVG=(y1+y2)/2 p3 = (xAVG,yAVG) m = (y2-y1)/(x2-x1) mP = -1/m L = [[x,mP*(x-xAVG)+yAVG] for x in range(-3,1)] l2 = line(L, rgbcolor=(1,0,0), aspect_ratio=1) l1+point(p1,color='red')+point(p2,color='red')+point(p3,color='black')+l2 
       
x1 = 1 y1 = 2 z1 = -1 x2 = -3 y2 = -5 z2 = 2 p1 = (x1,y1,z1) p2 = (x2,y2,z2) l1 = line([p1,p2]) xAVG = (x1+x2)/2 yAVG = (y1+y2)/2 zAVG = (z1+z2)/2 p3 = (xAVG,yAVG,zAVG) l1+point(p1,color='red')+point(p2,color='red')+point(p3,color='cyan') 
       
L = [[5*cos(pi*i/100),5*sin(pi*i/100)] for i in range(200)] l1 = line(L, rgbcolor=(1,0,0), aspect_ratio=1) L = [[5*cos(pi*i/100),1*sin(pi*i/100)] for i in range(200)] l2 = line(L, rgbcolor=(0,1,0), aspect_ratio=1) L = [[1*cos(pi*i/100),5*sin(pi*i/100)] for i in range(200)] l3 = line(L, rgbcolor=(0,0,1), aspect_ratio=1) l1+l2+l3 
       
L = [[(1+cos(pi*i/100))*cos(pi*i/100),(1+cos(pi*i/100))*sin(pi*i/100)] for i in range(200)] l1 = line(L, rgbcolor=(1,1,0), aspect_ratio=1) L = [[(1+2*cos(pi*i/100))*cos(pi*i/100),(1+2*cos(pi*i/100))*sin(pi*i/100)] for i in range(200)] l2 = line(L, rgbcolor=(0,1,1), aspect_ratio=1) L = [[(2+cos(pi*i/100))*cos(pi*i/100),(2+cos(pi*i/100))*sin(pi*i/100)] for i in range(200)] l3 = line(L, rgbcolor=(1,0,1), aspect_ratio=1) l1+l2+l3 
       
L = [[(1+sin(pi*i/100))*cos(pi*i/100),(1+sin(pi*i/100))*sin(pi*i/100)] for i in range(200)] l1 = line(L, rgbcolor=(1,1,0), aspect_ratio=1) L = [[(1+2*sin(pi*i/100))*cos(pi*i/100),(1+2*sin(pi*i/100))*sin(pi*i/100)] for i in range(200)] l2 = line(L, rgbcolor=(0,1,1), aspect_ratio=1) L = [[(2+sin(pi*i/100))*cos(pi*i/100),(2+sin(pi*i/100))*sin(pi*i/100)] for i in range(200)] l3 = line(L, rgbcolor=(1,0,1), aspect_ratio=1) l1+l2+l3 
       
a = 3 L = [[sin(a*pi*i/100)*cos(pi*i/100),sin(a*pi*i/100)*sin(pi*i/100)] for i in range(200)] l1 = line(L, rgbcolor=(0,1,1), aspect_ratio=1) l1 
       
sage: L = [[cos(pi*i/100)^3,sin(pi*i/100)^3] for i in range(200)] sage: polygon2d(L, rgbcolor=(3/4,1/4,1/4)) 
       
polygon3d? 
       

File: /home/sage/sage_install/sage-alpha/local/lib/python2.6/site-packages/sage/misc/decorators.py

Type: <type ‘function’>

Definition: polygon3d(*args, **kwds)

Docstring:

Draw a polygon in 3d.

INPUT:

  • points - the vertices of the polygon

Type polygon3d.options for a dictionary of the default options for polygons. You can change this to change the defaults for all future polygons. Use polygon3d.reset() to reset to the default options.

EXAMPLES:

A simple triangle:

sage: polygon3d([[0,0,0], [1,2,3], [3,0,0]])

Some modern art – a random polygon:

sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for _ in range(10)]
sage: polygon3d(v)

A bent transparent green triangle:

sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), alpha=0.7)

File: /home/sage/sage_install/sage-alpha/local/lib/python2.6/site-packages/sage/misc/decorators.py

Type: <type ‘function’>

Definition: polygon3d(*args, **kwds)

Docstring:

Draw a polygon in 3d.

INPUT:

  • points - the vertices of the polygon

Type polygon3d.options for a dictionary of the default options for polygons. You can change this to change the defaults for all future polygons. Use polygon3d.reset() to reset to the default options.

EXAMPLES:

A simple triangle:

sage: polygon3d([[0,0,0], [1,2,3], [3,0,0]])

Some modern art – a random polygon:

sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for _ in range(10)]
sage: polygon3d(v)

A bent transparent green triangle:

sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), alpha=0.7)
p = polygon3d([[0,0,0], [1,2,3], [3,0,0]],color='purple',aspect_ratio=1) p 
       
sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for x in range(10)] sage: polygon3d(v,color='orange',alpha=0.4) 
       
v=(sqrt(5.)/2-5/6, 5/6*sqrt(3.)-sqrt(15.)/2, sqrt(5.)/3) t=acos(sqrt(5.)/3)/2 t1=tetrahedron(aspect_ratio=(1,1,1), opacity=0.5).rotateZ(t) t2=tetrahedron(color='red', opacity=0.5).rotateZ(t).rotate(v,2*pi/5) t3=tetrahedron(color='green', opacity=0.5).rotateZ(t).rotate(v,4*pi/5) t4=tetrahedron(color='yellow', opacity=0.5).rotateZ(t).rotate(v,6*pi/5) t5=tetrahedron(color='orange', opacity=0.5).rotateZ(t).rotate(v,8*pi/5) show(t1+t2+t3+t4+t5, frame=False, zoom=1.2) 
       
sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=1) 
       
G = icosahedron(color='red') + sphere((1,2,3), 0.5, color='yellow') G.show(frame=false) 
       
S = sphere(opacity=0.8, aspect_ratio=[1,1,1]) L = line3d([(0,0,0),(2,0,0)], thickness=10, color='red') M = S + S.translate((2,0,0)) + L M.show(viewer='tachyon') 
       
t = Tachyon(xres=500,yres=500, camera_center=(2,0,0)) t.light((4,3,2), 0.2, (1,1,1)) t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0)) t.texture('t4', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1)) t.sphere((0,0.5,0), 0.2, 't2') t.sphere((0.5,0,0), 0.2, 't3') t.sphere((0,0,0.5), 0.2, 't4') t.show() 
       
t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0)) t.light((4,3,2), 0.2, (1,1,1)) t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1.0,0,0)) t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.3, opacity=1.0, color=(0,1.0,0)) t.texture('t2', ambient=0.2,diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0)) k=0 for i in srange(-1,1,0.05): k += 1 t.sphere((i,i^2-0.5,i^3), 0.1, 't%s'%(k%3)) t.show() 
       
t = Tachyon(xres=512,yres=512, camera_center=(2,0.5,0.5), look_at=(0.5,0.5,0.5), raydepth=4) t.light((4,3,2), 0.2, (1,1,1)) t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1.0,0,0)) t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.3, opacity=1.0, color=(0,1.0,0)) t.texture('t2', ambient=0.2, diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0)) k=0 for i in range(100): k += 1 t.sphere((random(),random(), random()), random()/10, 't%s'%(k%3)) t.show() 
       
t = Tachyon(xres=1000, yres=800, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4) t.light((10,3,2), 1, (1,1,1)) t.light((10,-3,2), 1, (1,1,1)) t.texture('black', color=(0,0,0)) t.texture('red', color=(1,0,0)) t.texture('grey', color=(.9,.9,.9)) t.plane((0,0,0),(0,0,1),'grey') t.cylinder((0,0,0),(1,0,0),.01,'black') t.cylinder((0,0,0),(0,1,0),.01,'black') E = EllipticCurve('37a') P = E([0,0]) Q = P n = 100 for i in range(n): Q = Q + P c = i/n + .1 t.texture('r%s'%i,color=(float(i/n),0,0)) t.sphere((Q[0], -Q[1], .01), .04, 'r%s'%i) t.show() # long time, e.g., 10-20 seconds 
       
t = Tachyon(xres=800,yres=800, camera_center=(2,5,2), look_at=(2.5,0,0)) t.light((0,0,100), 1, (1,1,1)) t.texture('r', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0)) for i in srange(0,50,0.1): t.sphere((i/10,sin(i),cos(i)), 0.05, 'r') t.texture('white', color=(1,1,1), opacity=1, specular=1, diffuse=1) t.plane((0,0,-100), (0,0,-100), 'white') t.show() 
       
f = lambda t: (t,t^2,t^3) t = Tachyon(camera_center=(5,0,4)) t.texture('t') t.light((-20,-20,40), 0.2, (1,1,1)) t.parametric_plot(f,-5,5,'t',min_depth=6) t.show() 
       
t = Tachyon(camera_center=(2,5,4), look_at=(2,0,0), raydepth=6) t.light((10,3,4), 1, (1,1,1)) t.texture('mirror', ambient=0.05, diffuse=0.05, specular=.9, opacity=0.9, color=(.8,.8,.8)) t.texture('grey', color=(.8,.8,.8), texfunc=3) t.plane((0,0,0),(0,0,1),'grey') t.sphere((4,-1,1), 1, 'mirror') t.sphere((0,-1,1), 1, 'mirror') t.sphere((2,-1,1), 0.5, 'mirror') t.sphere((2,1,1), 0.5, 'mirror') show(t) 
       
#A = matrix([[1,1],[-1,1]]) #D = [vector([0,0]), vector([1,0])] @interact def f(A = matrix([[1,1],[-1,1]]), D = '[[0,0],[1,0]]', k=(3..17)): print "Det = ", A.det() D = matrix(eval(D)).rows() def Dn(k): ans = [] for d in Tuples(D, k): s = sum(A^n*d[n] for n in range(k)) ans.append(s) return ans G = points([v.list() for v in Dn(k)]) show(G, frame=True, axes=False) 
       

Click to the left again to hide and once more to show the dynamic interactive window

%cython import numpy as np def mandelbrot_cython(float x0,float x1,float y0,float y1,int N=200, int L=50, float R=3): '''returns an array NxN to be plotted with matrix_plot ''' cdef int h, i, k m= np.zeros([N,N], dtype=np.int) for i in range(N): for k in range(N): c=complex(x0+i*(x1-x0)/N, y0+k*(y1-y0)/N) z=complex(0,0) h=0 while (h<L) and (abs(z)<R): z=z*z+c h+=1 m[i,k]=h return m 
@interact def showme_mandelbrot(x0=-2, y0=-1.5, side=3.0,N=(100*i for i in range(1,11)), L=(20*i for i in range(1,11)) ): time m=mandelbrot_cython(x0 ,x0 + side ,y0 ,y0 + side , N, L ) time show(matrix_plot(m),frame=False) 
       

Click to the left again to hide and once more to show the dynamic interactive window

@interact def mandel_plot(expo = slider(-10,10,0.1,2), \ formula = list(['mandel','ff']),\ iterations=slider(1,100,1,30), \ zoom_x = range_slider(-2,2,0.01,(-2,1)), \ zoom_y = range_slider(-2,2,0.01,(-1.5,1.5))): var('z c') f(z,c) = z^expo + c ff_m = fast_callable(f, vars=[z,c], domain=CDF) # messing around with fast_callable for i in range(int(iterations)/3): f(z,c) = f(z,c)^expo+c ff = fast_callable(f, vars=[z,c], domain=CDF) def mandel(z): c = z for i in range(iterations): z = ff_m(z,c) if abs(z) > 2: return z return z print 'z <- z^%s + c' % expo # calling ff three times, otherwise it fast_callable exceeds a recursion limit if formula is 'ff': func = lambda z: ff(ff(ff(z,z),z),z) elif formula is 'mandel': func = mandel complex_plot(func, zoom_x,zoom_y, plot_points=200, dpi=150).show(frame=True, aspect_ratio=1) 
       

Click to the left again to hide and once more to show the dynamic interactive window

@interact def julia_plot(expo = slider(-10,10,0.1,2), \ iterations=slider(1,100,1,30), \ c_real = slider(-2,2,0.01,0.5), \ c_imag = slider(-2,2,0.01,0.5), \ zoom_x = range_slider(-2,2,0.01,(-1.5,1.5)), \ zoom_y = range_slider(-2,2,0.01,(-1.5,1.5))): var('z') I = CDF.gen() f(z) = z^expo + c_real + c_imag*I ff_j = fast_callable(f, vars=[z], domain=CDF) def julia(z): for i in range(iterations): z = ff_j(z) if abs(z) > 2: return z return z print 'z <- z^%s + (%s+%s*I)' % (expo, c_real, c_imag) complex_plot(julia, zoom_x,zoom_y, plot_points=200, dpi=150).show(frame=True, aspect_ratio=1) 
       

Click to the left again to hide and once more to show the dynamic interactive window

julia_plot(-7,30,0.5,0.5,(-1.5,1.5), (-1.5,1.5)) 
       
z <- z^-7 + (0.500000000000000+0.500000000000000*I)
z <- z^-7 + (0.500000000000000+0.500000000000000*I)
#what about shaded regions for linear programming?