Exemplo n.º 1
0
    def think(self, dt, view, debugsurface):
        if self.waypoint_len() == 0:
            a = random.random() * math.pi * 2
            step = random.gauss(self.step_mean, self.step_mean / 3)
            self.waypoint_push(self.position + Vec2d(math.cos(a) * step, math.sin(a) * step))

        for o in view.obstacles:  # avoid obstacles
            if line_distance2(self.position, self.waypoint().position, o.p1, o.p2) <= self.radius ** 2:
                self.waypoint_clear()
                return
Exemplo n.º 2
0
    def line_is_traversable(self, p1, p2):
        """Check if line is collision free with static obstacles

        Returns True if a straight path between p1 and p2 is possible without
        colliding into static obstacles
        """
        for o in self.view.obstacles:
            if line_distance2(p1, p2, o.p1, o.p2) < self.min_distance2:
                return False
        return True
Exemplo n.º 3
0
    def think(self, dt, view, debugsurface):
        if self.waypoint_len() == 0:
            a = random.random() * math.pi * 2
            step = random.gauss(self.step_mean, self.step_mean / 3)
            self.waypoint_push(self.position + Vec2d(math.cos(a) * step, math.sin(a) * step))

        direction = self.waypoint().position - self.position
        for p in view.pedestrians:  # stop if any pedestrians are in the way
            if direction.angle(p.position - self.position) < math.pi / 2:
                self.waypoint_clear()
                return

        for o in view.obstacles:  # avoid obstacles
            if line_distance2(self.position, self.waypoint().position, o.p1, o.p2) <= self.radius ** 2:
                self.waypoint_clear()
                return
Exemplo n.º 4
0
    def freeprob_line(self, p1, p2, view, starttime):
        """ Free probability for moving from p1 to p2 starting on starttime """
        if p1 == p2:
            return self.freeprob_pedestrians(p1, view, starttime)

        for o in view.obstacles:
            if line_distance2(o.p1, o.p2, p1, p2) < (self.radius + self.FREEMARGIN) ** 2:
                return 0

        diff = p2 - p1
        length = diff.length()
        v = diff / length
        resolution = self.radius * 2
        numsegments = int(math.ceil(length / resolution))
        segmentlen = length / numsegments
        timediff = segmentlen / self.speed

        freeprob = 1.0
        for i in xrange(numsegments + 1):
            freeprob *= self.freeprob_pedestrians(p1 + v * i * segmentlen, view, starttime + i * timediff)

        return freeprob
Exemplo n.º 5
0
    def line_safeness(self, p1, p2, view, starttime):
        """ Free probability for moving from p1 to p2 starting on starttime
        """
        if p1 == p2:
            return self.static_safeness(p1, view, starttime)

        safedist2 = (self.radius + self.FREEMARGIN) ** 2

        for o in view.obstacles:
            if line_distance2(o.p1, o.p2, p1, p2) < safedist2:
                return 0

        diff = p2 - p1
        length = diff.length()
        v = diff * self.speed / length
        t = length / self.speed

        return self.line_pedestrian_safeness(
            position=p1,
            velocity=v,
            start_time=starttime,
            end_time=starttime + t,
            view=view
        )
Exemplo n.º 6
0
 def line_is_traversable(self, p1, p2):
     """Check if traversing in p1-p2 on a straight path is possible without colliding into static obstacles"""
     for o in self.view.obstacles:
         if line_distance2(p1, p2, o.p1, o.p2) < self.min_distance2:
             return False
     return True