def gene(cible, p): taille = 12 if p.getPerceptType() == "Home": taille = 20 # Distance par rapport au tir angle = self.towards(cible.getX(), cible.getY()) angle = Math.PI * angle / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) dist_x = ( p.getX() + t* p.getY()) / (c + s * t) dist_y = -p.getY()/c + t * dist_x #print self.getAddress().getName() + " --> " + str(dist_x) + " --- " + str(dist_y) return abs(dist_y) < taille and dist_x > 0 and dist_x< cible.distanceTo(Point())
def Perpendicular_line(imp, line_info): ## Calculates the parameters for a line that is ## perpendicular to an ROI line. This is the line ## that acts as the depth reference. angle, xbase, ybase, width, height, xend, yend, slope = line_info width, height, nChannels, nSlices, nFrames = imp.getDimensions() b = ybase - (slope*xbase) perp_angle = math.toRadians(angle - 90) slope_new_line = math.tan(perp_angle) return(slope_new_line, b)
def gene(cible, p): taille = 12 if p.getPerceptType() == "Home": taille = 20 # Distance par rapport au tir angle = self.towards(cible.getX(), cible.getY()) angle = Math.PI * angle / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) dist_x = (p.getX() + t * p.getY()) / (c + s * t) dist_y = -p.getY() / c + t * dist_x #print self.getAddress().getName() + " --> " + str(dist_x) + " --- " + str(dist_y) return abs(dist_y) < taille and dist_x > 0 and dist_x < cible.distanceTo( Point())
def eviteObstacles(percepts): dist1 = dist2 = 500 taille_robot = 20 liste_obstacles = [] for p in percepts: centre = Point() centre.setCoord(p.getX(), p.getY()) liste_obstacles.append(centre) # on dessine 2 droite paralleles a la direction # qui partent des bords du robot -> d1 : y = 12 et d2 : y = -12 # Dans nouveau repere : origine = self # rotation du repere de l'angle de direction courant direction = self.getHeading() angle = Math.PI * direction / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) for p in liste_obstacles: # centre_x, centre_y : centre de l'obstacle dans le repere centre_x = (p.getX() + t * p.getY()) / (c + s * t) centre_y = -p.getY() / c + t * centre_x # savoir quelle droite prendre if centre_x > 0: if centre_y >= 0 and centre_y <= 2 * taille_robot: y = centre_y - taille_robot dist1 = min( dist1, -Math.sqrt(taille_robot * taille_robot - y * y) + centre_x) elif centre_y < 0 and centre_y >= -(2 * taille_robot): y = centre_y + taille_robot dist2 = min( dist2, -Math.sqrt(taille_robot * taille_robot - y * y) + centre_x) if min(dist1, dist2) <= 100 and abs(dist1 - dist2) > 2: if dist1 < dist2: direction += 100 / dist1 else: direction -= 100 / dist2 self.setHeading(direction)
def eviteAmis(percepts): dist1 = dist2 = 500 taille_robot = 20 liste_obstacles = [] for p in percepts: centre = Point() centre.setCoord(p.getX(), p.getY()) liste_obstacles.append(centre) # on dessine 2 droite paralleles a la direction # qui partent des bords du robot -> d1 : y = 12 et d2 : y = -12 # Dans nouveau repere : origine = self # rotation du repere de l"angle de direction courant direction = self.getHeading() angle = Math.PI * direction / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) for p in liste_obstacles: # centre_x, centre_y : centre de l"obstacle dans le repere centre_x = ( p.getX() + t* p.getY()) / (c + s * t) centre_y = -p.getY()/c + t * centre_x # savoir quelle droite prendre if centre_x > 0: if centre_y >= 0 and centre_y <= 2*taille_robot: y = centre_y - taille_robot dist1 = min(dist1,-Math.sqrt(taille_robot*taille_robot - y*y) + centre_x) elif centre_y < 0 and centre_y >= -(2*taille_robot): y = centre_y + taille_robot dist2 = min(dist2,-Math.sqrt(taille_robot*taille_robot - y*y) + centre_x) if min(dist1, dist2) <= 100 and abs(dist1 - dist2) > 2: if dist1 < dist2: direction += 100/dist1 else: direction -= 100/dist2 self.setHeading(direction)