Ejemplo n.º 1
0
 def testDistancePointLine(self):
     '''
     distance_point_line - distance of a point from a line
     '''
     TO_TEST = [
                ((4, 4, 0),   (1, 1, 0),  (1, 0, 0),  3.0),
                ((-2, -1, 0), (4, 2, 0),  (-4, 8, 0), 6.708203932499369),
                ((2,-1, 2),   (-1, 0, 7), (4, 1, -2), 3.7416573867739413),
               ]
     for point, origin, vector, expected in TO_TEST:
         point, origin, vector = map(lambda x : Vector3(*x),
                                     [point, origin, vector])
         result = U.distance_point_line(point, origin, vector)
         self.assertAlmostEqual(result, expected)
Ejemplo n.º 2
0
 def __get_crossed_gates(self, plane):
     '''
     Return the list of gates (if any) that a given point of the edge on
     the aerospace corresponds to.
     '''
     crossed = []
     origin = Vector3(S.RADAR_RANGE, S.RADAR_RANGE)
     point = Vector3(*plane.position.xy)
     for gate in self.gates.values():
         vector = U.heading_to_v3(gate.radial)
         dist = U.distance_point_line(point, origin, vector)
         boundaries = ((plane.heading - S.GATE_TOLERANCE) % 360,
                       (plane.heading + S.GATE_TOLERANCE) % 360)
         if dist <= gate.width / 2 and \
            U.heading_in_between(boundaries, gate.radial) and \
            gate.bottom <= plane.altitude <= gate.top:
             crossed.append(gate)
     return crossed