def next(self, quantum=1): "State after quantum." self.time += quantum avspeed = (2 * self.speed + self.h_acc * quantum) / 2 avclimb = (2 * self.climb + self.v_acc * quantum) / 2 self.alt += avclimb * quantum self.speed += self.h_acc * quantum self.climb += self.v_acc * quantum distance = avspeed * quantum # Formula from <http://williams.best.vwh.net/avform.htm#Rhumb> # Initial point cannot be a pole, but GPS doesn't work at high. # latitudes anyway so it would be OK to fail there. # Seems to assume a spherical Earth, which means it's going # to have a slight inaccuracy rising towards the poles. # The if/then avoids 0/0 indeterminacies on E-W courses. tc = gps.Deg2Rad(self.course) lat = gps.Deg2Rad(self.lat) lon = gps.Deg2Rad(self.lon) lat += distance * math.cos(tc) dphi = math.log(math.tan(lat / 2 + math.pi / 4) / math.tan(self.lat / 2 + math.pi / 4)) if abs(lat - self.lat) < math.sqrt(1e-15): q = math.cos(self.lat) else: q = (lat - self.lat) / dphi dlon = -distance * math.sin(tc) / q self.lon = gps.Rad2Deg(math.mod(lon + dlon + math.pi, 2 * math.pi) - math.pi) self.lat = gps.Rad2Deg(lat)
def next(self, quantum=1): "State after quantum." self.time += quantum avspeed = (2 * self.speed + self.h_acc * quantum) / 2 avclimb = (2 * self.climb + self.v_acc * quantum) / 2 self.alt += avclimb * quantum self.speed += self.h_acc * quantum self.climb += self.v_acc * quantum distance = avspeed * quantum # Formula from <http://williams.best.vwh.net/avform.htm#Rhumb> # Initial point cannot be a pole, but GPS doesn't work at high. # latitudes anyway so it would be OK to fail there. # Seems to assume a spherical Earth, which means it's going # to have a slight inaccuracy rising towards the poles. # The if/then avoids 0/0 indeterminacies on E-W courses. tc = gps.Deg2Rad(self.course) lat = gps.Deg2Rad(self.lat) lon = gps.Deg2Rad(self.lon) lat += distance * math.cos(tc) dphi = math.log( math.tan(lat / 2 + math.pi / 4) / math.tan(self.lat / 2 + math.pi / 4)) if abs(lat - self.lat) < math.sqrt(1e-15): q = math.cos(self.lat) else: q = (lat - self.lat) / dphi dlon = -distance * math.sin(tc) / q self.lon = gps.Rad2Deg( math.mod(lon + dlon + math.pi, 2 * math.pi) - math.pi) self.lat = gps.Rad2Deg(lat)
def get_percent(value, max_value): """ Ritorna un numero che rappresenta la percentuale del valore passato rispetto al suo potenziale massimo. """ if max_value == 0: log.bug("max_value non è un parametro valido: 0") return 0 # ------------------------------------------------------------------------- if value > 0 and max_value < 0: max_value = math.mod(max_value) return 100 + ((value * 100) / max_value) elif value < 0 and max_value < 0: value = math.mod(value) max_value = math.mod(max_value) return -((value * 100) / max_value) else: return (value * 100) / max_value
def get_data(self, offset = 0, length = None): # need to add a check to make sure offset and length are within limits #offset >= 0 #offset + length <= len(self.inodes) * self.blocklayer.blocksize blocks = self.get_block_ids_for_byte_range(offset, length) data = b'' for block_idx in blocks: block = self.blocklayer.read_block(block_idx) data += block # cut off data to match byte offsets start_offset = math.mod(offset / self.blocklayer.blocksize) if(length <> None): end_offset = self.blocklayer.blocksize - math.mod(length / self.blocklayer.blocksize) else: end_offset = len(data) data = data[start_offset:end_offset] return(data)
def plot_accuracy(chunk_accuracy_list): avg_chunk_accuracy = [] n = 5 sum1 = 0 for i in range(1, len(chunk_accuracy_list)): sum1 = sum1 + chunk_accuracy_list[i - 1] if math.mod(i, n) == 0: avg_chunk_accuracy.append(sum1 / n) sum1 = 0 x = range(1, len(avg_chunk_accuracy) + 1) # x=range(1,len(chunk_accuracy_list)+1,1000) mp.pyplot.plot(x, avg_chunk_accuracy) mp.pyplot.show()
def simpsons(x,h,N): #Performs the Simpons rule (equation 1.12) #Input: x -- lower bound of the range of integration # h -- step-size # N -- number of lattices #Output: sum -- approximate integral #Add the contribution from the first and last points on the lattice points sum = myFunction(x) + myFunction(x+N*h) for i+1 in N-1: j = i+1 #Adds the contribution from the even placed lattice points if (math.mod(j,2) == 1) sum = sum + 4.0*myFunction(x+j*h) #Adds the contribution from the odd placed lattice points else sum = sum + 2.0*myFunction(x+j*h) sum = sum*h/3 #Apply leading coeffecient return sum
def mkfs(blocklayer): r""" new blocklayer with 100 4k blocks >>> from blocklayer import ram_blocklayer >>> bl = ram_blocklayer(100) >>> mkfs(bl) """ # 0 superblock # 1 first inodeblock # 2 root dir # 3 fs meta if(math.mod(bs / ctypes.sizeof(INODE))): logger.warn('blocksize is not a multiple of inodesize, space will be wasted and a lot of warnings will be thrown') bs = blocklayer.blocksize for x in range(10): blocklayer.trim_block(x) sb = blocklayer.read_block(0) ib = Inodeblock(count = math.floor(bs / ctypes.sizeof(INODE))) ib[0]
def mod(self): self.result = False self.current = math.mod(math.radians(float(txtDisplay.get()))) self.display(self.current)