def matchArc(arc): """Take the raytraced arc, negate the dispersion direction, and compute the translation and rotation transformations to match the two spectra """ #Create the second arc by negating the dispersion direction sh = np.shape(arc) arc = [arc[0], arc[1], np.zeros(sh[1]), np.ones(sh[1])] arc2 = np.copy(arc) arc2[1] = -arc2[1] #Transform second arc by pi/2 r = tr.rotation_matrix(pi / 2, [0, 0, 1]) arc2 = np.dot(r, arc2) #Get gradients dx = np.diff(arc2[0])[0] gr = np.gradient(arc2[1], dx) pdb.set_trace() #Apply rotation to match slopes angle = pi / 2 + np.arctan(gr[-1]) + np.arctan(gr[0]) print angle r2 = tr.rotation_matrix(-angle, [0, 0, 1]) arc3 = np.dot(r2, arc2) #Apply translation to match pdb.set_trace() ## arc3[0] = arc3[0] + (arc[0][-1]-arc3[0][0]) ## arc3[1] = arc3[1] + (arc[1][-1]-arc3[1][0]) t = tr.translation_matrix([(arc[0][-1]-arc3[0][0]),\ (arc[1][-1]-arc3[1][0]),\ 0.]) arc3 = np.dot(t, arc3) tra = np.dot(t, (np.dot(r2, r))) #Get even closer dist = np.sqrt((arc[0][0] - arc3[0][-1])**2 + (arc[1][0] - arc3[1][-1])**2) lever = np.sqrt((arc[0][0] - arc[0][-1])**2 + (arc[1][0] - arc[1][-1])**2) angle2 = dist / lever new = tr.rotation_matrix(angle2, [0, 0, 1], point=[arc3[0][0], arc3[1][0], 0]) tra2 = np.dot(new, tra) #Return transformation return tra2, angle, angle2, new, tra
def transformCoords_wMag(x,y,tx,ty,theta,mag): """Transforms coordinates x,y by magnifying x,y by a constant factor, then translating tx,ty and rotating theta about x Returns: x,y of new coords """ mag_x,mag_y = x*mag,y*mag trans = tr.translation_matrix([tx,ty,0]) rot = tr.rotation_matrix(theta,[0,0,1],point=[np.mean(x),np.mean(y),0]) pos0 = np.array((mag_x,mag_y,np.repeat(0.,np.size(x)),np.repeat(1.,np.size(x)))) pos1 = np.dot(trans,np.dot(rot,pos0)) return pos1[0],pos1[1]
def transformCoords(x,y,tx,ty,theta): """Transforms coordinates x,y by translating tx,ty and rotation theta about x Returns: x,y of new coords """ trans = tr.translation_matrix([tx,ty,0]) rot = tr.rotation_matrix(theta,[0,0,1],point=[np.mean(x),np.mean(y),0]) pos0 = np.array((x,y,np.repeat(0.,np.size(x)),np.repeat(1.,np.size(x)))) pos1 = np.dot(trans,np.dot(rot,pos0)) return pos1[0],pos1[1]
def makeLayout(arc, sepAngle): tra, angle = matchArc(arc) #Get nominal transformation for paired petal tra2 = np.dot(tr.rotation_matrix(angle / 2, [0, 0, 1]), tra) tra1 = tr.rotation_matrix(angle / 2, [0, 0, 1]) #Create the second arc by negating the dispersion direction sh = np.shape(arc) arc = [arc[0], arc[1], np.zeros(sh[1]), np.ones(sh[1])] arc2 = np.copy(arc) arc2[1] = -arc2[1] #Apply transformations arc2 = np.dot(tra2, arc2) arc1 = np.dot(tra1, arc) #Find center of second arc xc, yc = fit.circle(arc2[0], arc2[1], 0, 0)[0] #Rotate each petal about this point tra1 = np.dot(tr.rotation_matrix(sepAngle, [0, 0, 1], point=[xc, yc, 0]), tra1) tra2 = np.dot(tr.rotation_matrix(-sepAngle, [0, 0, 1], point=[xc, yc, 0]), tra2) #Add translation to second petal tra2 = np.dot(tr.translation_matrix([10 / np.sqrt(2), 10 / np.sqrt(2), 0]), tra2) #Now plot the petals with the correct translations pet1 = plotPetal(arc[0], arc[1], tra=tra1, color='blue') pet2 = plotPetal(arc[0], -arc[1], tra=tra2, color='red') #Plot dashed line between corners closest to arcs x1, x2, y1, y2 = pet1[1][0][3], pet2[1][0][2], pet1[1][1][3], pet2[1][1][2] plt.plot([pet1[1][0][3], pet2[1][0][2]], [pet1[1][1][3], pet2[1][1][2]], 'k--')
def collectFocalPlaneRays(z): tra2 = np.dot(tr.translation_matrix([40,-100,0]),\ tr.rotation_matrix(pi/2,[0,0,1,0])) rot2 = tr.rotation_matrix(pi / 2, [0, 0, 1, 0]) tra3 = np.dot(tr.translation_matrix([1000,-1000,0]),\ tr.rotation_matrix(-pi/2,[0,0,1,0])) rot3 = tr.rotation_matrix(-pi / 2, [0, 0, 1, 0]) tra4 = np.dot(tr.translation_matrix([1020,920,0]),\ tr.rotation_matrix(pi,[0,0,1,0])) rot4 = tr.rotation_matrix(pi, [0, 0, 1, 0]) f = open( '/home/rallured/Dropbox/Arcus/Raytrace/FocalPlaneLayout/160412_Rays.pkl', 'r') rays = pickle.load(f) f.close() rays2 = np.copy(rays) rays2 = [rays2[0],rays2[1],-rays2[2],rays2[3],\ rays2[4],-rays2[5],rays2[6],\ rays2[7],rays2[8],rays2[9]] rays3 = np.copy(rays) rays3 = [rays3[0],rays3[1],-rays3[2],rays3[3],\ rays3[4],-rays3[5],rays3[6],\ rays3[7],rays3[8],rays3[9]] rays4 = np.copy(rays) tran.itransform(rays2, 40, -100, 0, 0, 0, pi / 2) tran.itransform(rays3, 1000, 1000, 0, 0, 0, -pi / 2) tran.itransform(rays4, 1020, 920, 0, 0, 0, pi) #Plot to make sure plt.plot(rays[1], rays[2], '.') plt.plot(rays2[1], rays2[2], '.') plt.plot(rays3[1], rays3[2], '.') plt.plot(rays4[1], rays4[2], '.') #Transform everything up r = [rays, rays2, rays3, rays4] [tran.transform(ri, 0, 0, z, 0, 0, 0) for ri in r] [surf.flat(ri) for ri in r] plt.figure() [plt.plot(ri[1], ri[2], '.') for ri in r]