def update_pos_by_dist_and_dir(self, distance, direction): """ params: distance - distance went through direction - angles relative to the west (clockwise) """ dirRelativeNorth = Map.get_direction_relative_north(self.building, self.level, direction) northAt = Map.get_north_at(self.building, self.level) userDir = dirRelativeNorth + northAt # relative to map userDir = userDir % 360 if not self.nextLoc: self.nextLoc = self.get_next_location(self.pos[0], self.pos[1]) movingDir = Map.get_direction(self.pos[0], self.nextLoc["x"], self.pos[1], self.nextLoc["y"]) # relative to map relativeDir = movingDir - userDir # if relativeDir > 0, it's at user's rhs, else lhs if relativeDir > 180: relativeDir -= 360 if relativeDir < -180: relativeDir += 360 (x, y, newDir) = Map.get_direction_details(self.building, self.level, distance, direction + relativeDir) vec1X = self.pos[0] - float(self.nextLoc["x"]) vec1Y = self.pos[1] - float(self.nextLoc["y"]) vec2X = self.pos[0] + x - float(self.nextLoc["x"]) vec2Y = self.pos[1] + y - float(self.nextLoc["y"]) isSameDirection = (vec1X * vec2X + vec1Y * vec2Y > 0) isReachNextLoc = self.is_reach_node(self.nextLoc, self.pos[0] + x, self.pos[1] + y) isWentPass = not isSameDirection and not isReachNextLoc if isWentPass: self.reachedLoc.append(self.nextLoc["nodeName"]) self.update_pos(x, y)
def get_next_location_details(self, direction, x, y): """ params: current user's direction (relative to north 0~360d), current x & y pos return: distance to next loc, direction to next loc (relative to user) & next loc's node """ nextLocNode = self.get_next_location(x, y) if self.nextLoc and self.nextLoc['nodeName'] in self.reachedLoc: self.prevLoc = self.nextLoc self.nextLoc = nextLocNode dist = Map.get_distance(nextLocNode["x"], x, nextLocNode["y"], y) northAt = Map.get_north_at(self.building, self.level) userDir = direction + northAt # relative to map userDir = userDir % 360 movingDir = Map.get_direction(x, nextLocNode["x"], y, nextLocNode["y"]) # relative to map relativeDir = movingDir - userDir # if relativeDir > 0, it's at user's rhs, else lhs if relativeDir > 180: relativeDir -= 360 if relativeDir < -180: relativeDir += 360 return relativeDir, dist, nextLocNode