Example #1
0
    def __init__(self, edge_id, p0, p1, name, lanes):
        self.id = edge_id
        self.p0 = p0
        self.p1 = p1
        self.name = name
        self.lanes = lanes
        self.distance = math_utils.distance(p0, p1)

        self.dx = self.p1.x - self.p0.x
        self.dy = self.p1.y - self.p0.y
        self.length = math_utils.pythag(self.dx, self.dy)
        self.unit_x = self.dx / self.length
        self.unit_y = self.dy / self.length

        self.lines = []
        self.width = 2
        self.way_gap = 0  # size of gap between each road direction
        self.lane_gap = 4  # size of gap between lines
        self.click_threshold = self.width * self.lanes

        for i in range(lanes):
            u0 = self.get_lane_adjusted_point(self.p0.x, self.p0.y, i)
            u1 = self.get_lane_adjusted_point(self.p1.x, self.p1.y, i)
            self.lines.append(self.create_line(u0, u1, self.width))
        self.text = self.create_text()
Example #2
0
    def calc_segment_len(self, name, df_ind_1, df_ind_2, fill_gaps=False):
        """
        Calculate the length of a segment formed by two points, specified
        by df_ind_1 and df_ind_2.

        Parameters:
            name (str): identifier for the resulting segment
            df_ind_1 (int): the dataframe index of the first point
                            that forms the segment
            df_ind_2 (int): the dataframe index of the second point 
                            that forms the segment
            fill_gaps (bool): when set to True, intopolate gaps to fill in
                              NaN values
        
        Returns:
            Nothing; adds the segment identified by name to self.datastore
        """
        self.duplicate_name_check(name)
        seg_arr = np.empty(self.nframes)

        print("\nStarting calculating length of segment", name,
              "between df indices", df_ind_1, "and", df_ind_2)
        for frame in tqdm(range(self.startframe, self.endframe)):
            seg_arr[frame] = math_utils.distance(self.df_x, self.df_y,
                                                 df_ind_1, df_ind_2, frame)

        if fill_gaps == True:
            seg_arr = math_utils.interpolate_gaps(seg_arr)

        self.datastore[name] = seg_arr
        print("Successfully calculated length of segment", name,
              "between df indices", df_ind_1, "and", df_ind_2)
Example #3
0
 def is_inside(self, another_circle):
     ''' Checks if this circle is fully inside another_circle '''
     if self.radius >= another_circle.radius:
         return None
     else:
         bigger_circle = another_circle
         smaller_circle = self
         return distance(bigger_circle.center, smaller_circle.center) + smaller_circle.radius < bigger_circle.radius
Example #4
0
 def is_inside_mutual(self, another_circle):
     ''' Checks if this circle is fully inside another_circle or the opposite.'''
     radius_diff = self.radius - another_circle.radius
     if radius_diff > 0:
         bigger_circle = self
         smaller_circle = another_circle
     elif radius_diff == 0:
         # None of them can be inside the other
         return None
     else:
         smaller_circle = self
         bigger_circle = another_circle
     return distance(bigger_circle.center, smaller_circle.center) + smaller_circle.radius < bigger_circle.radius
Example #5
0
 def collide_circle(self, another_circle, moved_center=(None, None), from_container_obj=False):
     ''' Checks if this circle intersects with another_circle. '''
     if not (len(moved_center) == 2):
         raise AttributeError("moved_center must be of the form (x,y)")
     _center = self.center
     moved_center = list(moved_center)
     if moved_center[0] is None:
         moved_center[0] = _center[0]
     if moved_center[1] is None:
         moved_center[1] = _center[1]
     # temporarily move self to moved_center and shift back later
     self.center = moved_center
     does_collide = (distance(self.center, another_circle.center) <= (
         self.radius + another_circle.radius))
     self.center = _center
     if does_collide:
         if from_container_obj:
             to_return = another_circle.container_obj
         else:
             to_return = another_circle
     else:
         to_return = False
     return to_return
Example #6
0
 def sphere_beam(self):
     return distance([self.xmax, self.ymax, self.zmax],
                     [self.xmin, self.ymin, self.zmin]) / 2.0
Example #7
0
 def intersect(self, segment):
     tris = self.intersect_tris(segment)
     if tris:
         return min(tris, key=lambda x: distance(x[1], segment[0]))
     return None
Example #8
0
 def sphere_beam(self):
     return distance([self.xmax, self.ymax, self.zmax],
             [self.xmin, self.ymin, self.zmin]) / 2.0
Example #9
0
 def clicked(self, p):
     clicked_p0_dist = math_utils.distance(p, self.p0)
     clicked_p1_dist = math_utils.distance(p, self.p1)
     if clicked_p0_dist + clicked_p1_dist <= self.distance + self.click_threshold:
         return True
     return False
Example #10
0
 def distance(self, x, y):
     point_ = (x, y)
     return distance(self.center, point_)