def test_angle(self): l1 = Line((0, 0), (0, 1)) l2 = Line((0, 0), (1, 0)) l3 = Line((0, 0), (1, 1)) self.assertEqual(l1.angle(l2), 90) self.assertAlmostEqual(l1.angle(l3), 45, 4) l2.general_equation()
def filter_lifelines(lifelines, vp1): """ Filters given trajectories by those which have direction ti the first vanishing point. :param lifelines: given trajectories :param vp1: detected vanishing point :return: filtered trajectories """ filtered = [] for lifeline in lifelines: line_to_vp = Line(lifeline[0], vp1.point) try: lifeline_line = Line(lifeline[0], lifeline[-1]) except SamePointError: continue if constants.TRACKER_TRAJECTORY_MIN_ANGLE < lifeline_line.angle(line_to_vp) < constants.TRACKER_TRAJECTORY_MAX_ANGLE: continue elif lifeline[0][1] < lifeline[-1][1]: continue else: filtered.append(lifeline) return filtered
def add_line(self): """ Adds new line to storage """ try: new_line = Line(self.point1, self.point2) if new_line.angle(Line.horizontal_line()) != 0: self.selected.append(Line(self.point1, self.point2)) except SamePointError: pass
def test_angle_019(self): l1 = Line((1, 2), (3, 5)) l2 = Line((3, 4), (2, 5)) self.assertAlmostEqual(l1.angle(l2), 78.7, 1)
def test_angle_90(self): l1 = Line((0, 1), (0, 0)) l2 = Line((0, 0), (1, 0)) self.assertEqual(l1.angle(l2), 90.)