示例#1
0
 def testIntersectSegment(self):
     '''
     intersect_by_points - intersect two lines
     '''
     # Format: list of points, expected result
     POSITIVES = [([(-1,-1), (1,1), (-1,1), (1,-1)], (0,0)  ),
                  ([(-1,0),  (1,0), (0,1),  (0,-1)], (0,0)  ),
                  ([(0,0),   (2,2), (2,0),  (0,2) ], (1,1)  ),
                  ([(0,0),   (2,1), (1,0),  (1,2) ], (1,0.5))]
     NEGATIVES = [([(-1,-1), (1,1), (5,5),  (6,6) ], (None, 'separation')),
                  ([(0,0),   (7,7), (0,0),  (7,7) ], (None, 'overlapping')),
                  ([(0,0),   (0,9), (2,0),  (2,9) ], (None, 'parallelism'))]
     for points, result in POSITIVES:
         res = U.segment_intersection(*points)
         self.assertEqual(res[1], 'intersection')
         self.assertAlmostEqual(res[0][0], result[0], 4)
         self.assertAlmostEqual(res[0][1], result[1], 4)
     for points, result in NEGATIVES:
         res = U.segment_intersection(*points)
         self.assertEqual(res, result)
示例#2
0
 def set_intersection_point(self):
     '''
     Set and return self.ip, the 2D intersection point between current
     plane heading and the ILS glide path.
     '''
     pl = self.plane
     p1 = pl.position.xy
     p2 = (pl.position + pl.velocity.normalized()*S.RADAR_RANGE*3).xy
     p3 = self.foot.xy
     p4 = (Vector3(*self.foot) + -self.ils.normalized()*S.RADAR_RANGE*3).xy
     self.ip, comment = U.segment_intersection(p1, p2, p3, p4)
     # If no point is due to overlapping, set the point as present position
     # of the plane.
     if comment == 'overlapping':
         self.ip = self.plane.position.xy
     # If there is a point, convert it to vector
     if self.ip:
         self.ip = Vector3(*self.ip)
     return self.ip