def setscan(pointList): circles = [] for center in pointList: for boundary in pointList: if center == boundary: continue centerPoint = geometry.point(center[0][0], center[0][1], center[1]) circles.append( geometry.circle(centerPoint, centerPoint.euclideanDistance(boundary[0]))) for enumurateCircle in circles: B = totalCases * (enumurateCircle.area() / UsArea) c = 0 for p in pointList: ConsideredPoint = geometry.point(p[0][0], p[0][1], p[1]) if enumurateCircle.LieInside(ConsideredPoint): c += ConsideredPoint.a logLRz = 0 #print(totalCases,B,c) if totalCases == c: logLRz = -math.inf elif c > B: logLRz += c * math.log(c / B) logLRz += (totalCases - c) * math.log( (totalCases - c) / (totalCases - B)) enumurateCircle.logLRz = logLRz return circles
def solve(self,**kwargs): try: if self.solver not in Eligible[self.mode]: print 'Error:'+self.solver+' solver not found for '+self.mode return except KeyError: print 'Error: Mode '+self.mode+' not supported' return if self.mode=='2D': for tID in gx.TargetDic.keys(): tar=gx.TargetDic[tID] if len(tar.measures)<self.apt: continue cA=[] for tup in tar.measures.items(): landmark=tup[0] c=gx.AnchorDic[landmark].loc ms=[xx[0] for xx in tup[1]] ws=[xx[1] for xx in tup[1]] # considering all measurements for xx in ms: cA.append(gm.circle(c,xx)) if self.solver=='LSE': try: tar.eloc = ml.lse(cA,cons=False) tar.status=1 except: tar.status=-1 elif self.solver=='LSE_GC': try: tar.eloc = ml.lse(cA) except cornerCases: self.status=-1
def solve(self, **kwargs): for tID in self.TargetDic.keys(): tar = self.TargetDic[tID] cA = [] for tup in tar.measures: landmark = tup[0] c = self.AnchorDic[landmark].loc d = tup[1] cA.append(gm.circle(c, d)) if self.solver == 'LSE': tar.loc = mx.lse(cA, mode=self.mode, cons=False) elif self.solver == 'LSE_GC': try: tar.loc = mx.lse(cA, mode=self.mode, cons=True) except mx.cornerCases as cc: if cc.tag == 'Disjoint': print tar.ID + ' could not be localized by LSE_GC' else: print 'Unknown Error in localizing ' + tar.ID elif self.solver == 'CCA': if not self.detail: tar.loc, n = mx.CCA(cA, mode=self.mode, detail=False) return n else: tar.loc, n, P, iP = mx.CCA(cA, mode=self.mode, detail=True) return (n, P, iP)
def solve(self, **kwargs): for tID in self.TargetDic.keys(): tar = self.TargetDic[tID] cA = [] for tup in tar.measures: landmark = tup[0] c = self.AnchorDic[landmark].loc d = tup[1] cA.append(geometry.circle(c, d)) # Solve using LSE tar.loc = methods.lse(cA)
def draw_arm(self): base_radius = self.model.get_disc_radius()/10. # offset between center of disc and pivot of arm arm_offset = [0, -self.model.get_arm_length()] # points in the arm head # (converted to local coords from greg's VB code head_pts = [ [-0.04971916, 0.94869806-1], [-0.06975647, 0.99756405-1], [-0.05390603, 1.02858842-1], [-0.02722403, 1.03964362-1], [-0.04361939, 0.99904822-1], [-0.03046844, 0.96952136-1], [ 0. , 0.96 -1], [ 0.03046844, 0.96952136-1], [ 0.04361939, 0.99904822-1], [ 0.02722403, 1.03964362-1], [ 0.05390603, 1.02858842-1], [ 0.06975647, 0.99756405-1], [ 0.04971916, 0.94869806-1], ] # scale the points in the head to match the base, and put the head into # the center of the disk head_pts = transform( head_pts, offset=[0, self.model.get_arm_length()], scale=10*base_radius ).tolist() # points that make up a vertical arm pts = [ # "base" circle(base_radius, end=-180), # line across base [[-base_radius,0], [base_radius,0]], # arm head, with body attached [[-base_radius,0]] + head_pts + [[base_radius,0]], ] # arm angle in world coordinates world_arm_angle = \ self.arm_zero + self.arm_angle_direction*self.model.get_arm_angle() transformed = [ transform(pts, offset=arm_offset, angle=world_arm_angle) for pts in pts ] return transformed
def draw_disc(self): disc_radius = self.model.get_disc_radius() # points that make up a disc with marks # n.b. that the disc center is at the origin of the world pts = [circle(disc_radius, resolution=50)] # 8 radial lines, evenly spaced pts += [ radial_line(0.9*disc_radius, disc_radius, angle=theta) for theta in np.linspace(0,360,12) ] # disc angle in world coordinates world_disc_angle = self.disc_angle_direction*self.model.get_disc_angle() transformed = [ transform(pts, angle=world_disc_angle) for pts in pts ] return transformed
window = pygame.display.set_mode((700, 500)) r1 = array([1,70]) r2 = array([1,71]) v = array([.1,.1]) center = (120, 100) while True: r1[0] = r1[0] + 1 refraction_map.clear() print "filling" make_prism(refraction_map) om.fill(geometry.circle(center,50), 1.5) om.fill(geometry.circle(center,51), 1.0) window.fill((0,0,0)) print "drawing" for (x,y) in reflection_map: drawpoint((x,y), (0,0,255)) for (x,y) in refraction_map: if refraction_map[x,y][1] == 1.0: drawpoint((x,y), (0,255,255)) else: drawpoint((x,y), (0,255,0)) if refraction_map[x,y][0] == (0,0): drawpoint((x,y), (255,0,0)) print "rendering" p1 = photon(r1,v,1.0,None)
[1235, 0.223646465, 8.75160691], [1240, 0.225419043, 8.78850408], [1245, 0.227198776, 8.82539343], [1250, 0.228985663, 8.86227506], [1255, 0.230779702, 8.89914907], [1260, 0.232580893, 8.93601553], [1265, 0.234389235, 8.97287454], [1270, 0.236204726, 9.00972619], [1275, 0.238027366, 9.04657055], [1280, 0.239857155, 9.08340771], [1285, 0.24169409, 9.12023775], [1290, 0.24353817, 9.15706076], [1295, 0.245389396, 9.1938768], [1300, 0.247247766, 9.23068595]]) res[:, 0] = res[:, 0] * 1e-3 Ag = mt.DiscreteIndex(np.vstack([res[:, 0], res[:, 1]]).T, np.vstack([res[:, 0], res[:, 2]]).T, name="Ag LP300") Lx, Ly = 1.0, 1.0 mat = mt.SpatialMaterial.from_pair( Air, Ag, geo.circle(Lx / 2, Ly / 2, 0.3 * (Lx + Ly) / 4)) # # k = c.KVector.from_periodic( # wl = 0.5, # aoi = 0, # inj_mat = Air, # Lambda_x = Lx, # Lambda_y = Ly, # N = 10, # M = 10) # # er = mat.er(0.5,k.X.flatten(),k.Y.flatten()).reshape(k.X.shape) # # plt.matshow(er.real) # plt.colorbar() # plt.show()
dimension_x = int(input("Please enter length of the side this square: ")) print("The field of this figure is: ", geometry.square(dimension_x)) elif figure.lower() == 'r': dimension_x = int( input("Please enter length of the one side this rectangle: ")) dimension_y = int(input("And the other side has dimension: ")) print("The field of this figure is: ", geometry.rectangle(dimension_x, dimension_y)) elif figure.lower() == 't': dimension_a = int(input("Please enter length of the triangle base: ")) dimension_h = int(input("And its height: ")) print("The field of this figure is: ", geometry.triangle(dimension_a, dimension_h)) elif figure.lower() == 'c': dimension_r = int(input("Please enter length of the radius: ")) print("The field of this figure is: ", geometry.circle(dimension_r)) elif figure.lower() == 'rh': dimension_e = int( input("Please enter length of the one diagonal this rhombus: ")) dimension_f = int(input("And the other diagonal has dimension: ")) print("The field of this figure is: ", geometry.rhombus(dimension_e, dimension_f)) elif figure.lower() == 'tr': dimension_a = int(input("Please enter length of the trapezium base: ")) dimension_b = int(input("And the other base has dimension: ")) dimension_h = int(input("And its height: ")) print("The field of this figure is: ", geometry.trapezium(dimension_a, dimension_b, dimension_h)) else: print("Something went wrong...")