def _find_p2p_angles_of_pnts(self, indx0, indx1): """Tabulate point to point angle of a serries of adjacent points.""" indexlist = [indx for indx in range(indx0, indx1)] slopelist = [] for indx in indexlist: slope = geo.p2p_angle(points[indx].xy, points[indx + 1].xy) slopelist.append(slope) return zip(indexlist, slopelist)
def scan_and_plan(nmbr=None): """Scan, save data and analyze. Return course & distance to open sector. """ if nmbr is None: nmbr = '' data = save_scan(nmbr) pscan = proscan.ProcessScan(data) logger.debug(f"Regions = {pscan.regions}") logger.debug(f"Zero Regions = {pscan.zero_regions}") # find indexes of non-zero regions sorted by number of points long_regs = pscan.regions_by_length() for idx in pscan.zero_regions: long_regs.remove(idx) # find just left region and right region long2regs = long_regs[:2] long2regs.sort() try: left_region, right_region = long2regs except ValueError: pscan.map(seq_nmbr=nmbr, display_all_points=True) return 0, 0 # find 'far' end of L & R regions as it will be the constriction left_pnt_indx = pscan.regions[left_region][-1] right_pnt_indx = pscan.regions[right_region][0] # find coords of each point left_pnt = pscan.points[left_pnt_indx].xy right_pnt = pscan.points[right_pnt_indx].xy logger.debug(f"Left point: {left_pnt}") logger.debug(f"Right point: {right_pnt}") # construct waypoint halfway between left and right points waypnt = geo.midpoint(left_pnt, right_pnt) # Path to travel from origin to waypoint (in center of gap) r = int(geo.p2p_dist((0, 0), waypnt)) theta = int(geo.p2p_angle((0, 0), waypnt)) # w/r/t +X direction course = theta - 90 # relative to +Y direction # print results and display map logger.debug(f"Relative course: {course}") logger.debug(f"Travel Distance: {r}") pscan.map(seq_nmbr=nmbr, display_all_points=True) return course, r
def get_line_parameters(self, segment): """Return a tuple of the parameters of line segment. segment is a tuple of the inexes of the segment end points parameter acronym: 'clad' for (coords, length, angle, distance) """ start_idx = segment[0] end_idx = segment[1] start_coords = self.points[start_idx].get("xy") end_coords = self.points[end_idx].get("xy") line = geo.cnvrt_2pts_to_coef(start_coords, end_coords) coords = (start_coords, end_coords) length = geo.p2p_dist(start_coords, end_coords) angle = geo.p2p_angle(start_coords, end_coords) dist = geo.p2line_dist((0, 0), line) # perp distance to line return (coords, length, angle, dist)