def create_path(a, b, contour, distancia, dir=0): conf_1 = -90 conf_2 = -1 conf_3 = "left" conf_4 = 0 if dir == 1: conf_3 = "right" path = [] contorno_points = [] for c in contour: c = utils.to_utm(c) utm_pos = Point(c.x, c.y) contorno_points.append(utm_pos) a2 = utils.to_utm(a) a_utm = Point(a2.x, a2.y) b2 = utils.to_utm(b) b_utm = Point(b2.x, b2.y) ab_course = utils.bearing(a_utm, b_utm) a_utm = utils.offset(a2, ab_course - 90, distancia * 80) b_utm = utils.offset(b2, ab_course - 90, distancia * 80) a2, b2 = utils.extend(a_utm, b_utm) AB = LineString([a2, b2]) contorno = Polygon(contorno_points) eroded = contorno.buffer(-distancia, resolution=16, join_style=1) line = AB.intersection(eroded) for x in range(1, 200): ab_1 = AB.parallel_offset(x * distancia, conf_3) line = ab_1.intersection(eroded) if (line.geom_type == "LineString"): if (len(line.coords) > 1): p1 = 1 p2 = conf_2 if x % 2 == 0: p1 = 0 p2 = -conf_2 centro = utils.offset(utils.toCoord(line.coords[p1]), ab_course + conf_1, distancia / 2) radius = distancia / 2 start_angle, end_angle = 90 - ab_course - 90, 90 - ab_course + 90 # In degrees if x % 2 == 0: start_angle, end_angle = 90 - ab_course + 90, 90 - ab_course - 90 numsegments = 200 theta = np.radians( np.linspace(start_angle, end_angle, numsegments)) x = centro.x + (radius * np.cos(theta)) * p2 y = centro.y + (radius * np.sin(theta)) * p2 arc = LineString(np.column_stack([x, y])) for c in arc.coords: path.append(Point(c)) final = LineString(path) path2 = [] for x in range(0, int(final.length / 2)): p = final.interpolate(x * 2) path2.append(p) return path2
def move(LatLon): global old_pos, init, old_bearing, mesh, bearings, tractor utm_pos = Coordinate(x=LatLon.x, y=LatLon.y) if init is False: tractor.m_p_s = 2 tractor.run() init = True old_pos = utm_pos scene.camera.pos = vec(utm_pos.x, 4, utm_pos.y - 50) scene.camera.axis = vec(0, -4, -50) obj = [] for x in range(-50, 50): for y in range(-50, 50): a = Coordinate(x=utm_pos.x + x * 500, y=utm_pos.y + y * 500 + 500) b = Coordinate(x=utm_pos.x + x * 500 + 500, y=utm_pos.y + y * 500 + 500) c = Coordinate(x=utm_pos.x + x * 500 + 500, y=utm_pos.y + y * 500) d = Coordinate(x=utm_pos.x + x * 500, y=utm_pos.y + y * 500) Q = quad( canvas=None, v0=vertex(pos=vec(a.x, -1, a.y)), v1=vertex(pos=vec(b.x, -1, b.y)), v2=vertex(pos=vec(c.x, -1, c.y)), v3=vertex(pos=vec(d.x, -1, d.y)), ) obj.append(Q) compound(obj, canvas=scene, color=vec(0, .60, 0)) else: curso = utils.bearing(utm_pos, old_pos) a = utils.offset(utm_pos, curso - 90, distance / 2) b = utils.offset(utm_pos, curso + 90, distance / 2) c = utils.offset(old_pos, old_bearing + 90, distance / 2) d = utils.offset(old_pos, old_bearing - 90, distance / 2) Q = quad( v0=vertex(pos=vec(a.x, .5, a.y), color=color.yellow), v1=vertex(pos=vec(b.x, .5, b.y), color=color.yellow), v2=vertex(pos=vec(c.x, .5, c.y), color=color.yellow), v3=vertex(pos=vec(d.x, .5, d.y), color=color.yellow), ) qobj.append(Q) left.append(vec(a.x, .5, a.y)) right.append(vec(b.x, .5, b.y)) old_bearing = curso old_pos = utm_pos bearings.pop() bearings.insert(0, curso) curso = sum(bearings) / len(bearings) camera = utils.offset(utm_pos, curso, 300) x, z = utils.vector(curso + 180) #scene.camera.pos=vec(camera.x, 100, camera.y) #scene.camera.axis=200*vec(x, -0.3 , z) tractor_3d.pos = tractor.get_vec(1.5)
def test_offset(self): """ Package together the properties we want for the date offset function into a single test """ # Basic function: single business day offset result = utils.offset(datetime.datetime(2013, 11, 11), 1) self.assertEqual(result, datetime.datetime(2013, 11, 12)) # Check one week offset result = utils.offset(datetime.datetime(2013, 11, 14), -5) self.assertEqual(result, datetime.datetime(2013, 11, 7)) # Check we move forward across a weekend correctly # - if we land on a saturday result = utils.offset(datetime.datetime(2013, 11, 13), 3, 'BD') self.assertEqual(result, datetime.datetime(2013, 11, 18)) # - if we land on a sunday result = utils.offset(datetime.datetime(2013, 11, 13), 4, 'bd') self.assertEqual(result, datetime.datetime(2013, 11, 18)) # And backward across a weekend result = utils.offset(datetime.datetime(2013, 11, 11), -1) self.assertEqual(result, datetime.datetime(2013, 11, 8)) # Check we bridge two weekends successfully result = utils.offset(datetime.datetime(2013, 11, 11), -7) self.assertEqual(result, datetime.datetime(2013, 10, 31)) # Check one month move result = utils.offset(datetime.datetime(2013, 11, 11), -1, 'M') self.assertEqual(result, datetime.datetime(2013, 10, 11)) # Check one month move that lands on a weekend moves to the # next business day - also check case insensitivity result = utils.offset(datetime.datetime(2013, 11, 12), -1, 'm') self.assertEqual(result, datetime.datetime(2013, 10, 11)) # Check one year move result = utils.offset(datetime.datetime(2013, 11, 12), 1, 'Y') self.assertEqual(result, datetime.datetime(2014, 11, 12)) # Check one year move that lands on a weekend moves to the # next business day - also check case insensitivity result = utils.offset(datetime.datetime(2013, 11, 15), 1, 'y') self.assertEqual(result, datetime.datetime(2014, 11, 17)) # Check exception is thrown if the period isn't recognised self.assertRaises(ValueError, utils.offset, datetime.datetime(2013, 11, 11), 1, 'X')
def idx_to_freq_mean_periods(idx, hz): ''' compute freq by taking mean period length in sample ''' diff = [b - a for a, b in offset(idx)] if diff: mean = sum(diff) / len(diff) return hz / mean else: return 0
def cross_err(pos, nav, path): print(nav) print(pos.x, pos.y) position = utils.offset(pos, nav, 4) print(position.x, position.y) punto = nearest_points(position, path)[1] curso = utils.bearing(position, punto) lado = utils.get_diff(nav, curso) distancia = punto.distance(position) distancia = math.copysign(distancia, lado) return distancia
def get_idx(signal): ''' calculate frequency of square wave use offset list to find the 0->1 transitions equivalent to: idx = [i for i, (a,b) in enumerate(offset(signal)) if (a,b) == (0,1)] ''' idx = [] for i, (a, b) in enumerate(offset(signal)): if (a, b) == (0, 1): idx.append(i) return idx
def main(args): root = args.path if not check(root): raise ValueError("Warning! Root directory isn't valid") max_dep = args.depth max_file = args.file assert max_dep > 0 and max_file > 0 print("{Visual Tree}") dir_count = 0 file_count = 0 for path, _, files in sorted(filtered_walk(root, depth=max_dep)): level = offset(root, path) base = os.path.basename(path) if level == 1: print(path) else: print(INDENT * level + SYMBOL + base) dir_count += 1 # display files level += 1 local_count = 0 display = True for file in sorted(files): file_count += 1 local_count += 1 if display: print(INDENT * level + SYMBOL + file) if local_count == max_file + 1: display = False print(INDENT * level + SYMBOL + "...") summary(root, dir_count, file_count)
def date_sequence(start, end): dte = start while dte <= end: yield dte dte = utils.offset(dte, 1)
def move(self): while True: self.bearing += self.direccion * -0.1 l = utils.offset(self.location, self.bearing, self.m_p_s / 10) self.location = l time.sleep(.01)
scene.append_to_caption('D ') def S3(s): tractor.pid.Kd = s.value slider(bind=S3, max=1, value=tractor.pid.Kd) scene.append_to_caption('\n\n') while True: if len(qobj) > 1000: qtemp = compound(qobj, canvas=scene, color=color.yellow) for obj in qobj: obj.visible = False del obj qobj = [] move(tractor.location) #print(tractor.location," Bearing:",tractor.bearing) d = (Point(tractor.location.x, tractor.location.y)) point, dist = nav.get_target(d, path) direct_bearing = utils.bearing(d, point) tractor.doblar((direct_bearing - tractor.bearing) + desv) #print("Dist: ","{0:0.2f}".format(dist),"m. WP_course: ","{0:0.2f}".format(wp_bearing),"deg. Direct_course: ","{0:0.2f}".format(direct_bearing),"deg. Target: ","{0:0.2f}".format(target),"deg.") #print("{0:0.2f}".format(c.x),";","{0:0.2f}".format(c.y)) camera = utils.offset(tractor.location, tractor.bearing, -150) x, z = utils.vector(tractor.bearing) scene.camera.pos = vec(camera.x, 70, camera.y) scene.camera.axis = 120 * vec(x, -0.3, z)