def check_possible_intersection(self, p, a): # check for parallel lines if((self.angle%np.pi) == (a%np.pi)): return False # create two temporary points for the line endpoints l1 = Point(self.p1.x, self.p1.y) l2 = Point(self.p2.x, self.p2.y) # move the points to 0 l1.translate_XY(-p.x,-p.y) l2.translate_XY(-p.x,-p.y) # rotate the temp points to match the ray l1.rotate(-a) l2.rotate(-a) # if the sign of each y component are the same, intersection is impossible if(round(l1.y,10) * round(l2.y,10) > 0): return False ''' X check - check the x normalized to y sum is greater than 0 - the ray is currently at angle 0, so lines that have negative weight have an intersection point in -x ''' if l1.y == 0: return l1.x > 0 elif l2.y == 0: return l2.x > 0 else: normal = l1.x/abs(l1.y) + l2.x/abs(l2.y) return normal > 0
def test_rotate45(self): a = Point(1, 1) rotated_a = Point.rotate(a, 45) self.assertEqual(rotated_a, Point(1.1102230246251565e-16, 1.414213562373095))
def test_rotate_minus90(self): a = Point(3, 4) rotated_a = Point.rotate(a, -90) self.assertEqual(rotated_a, Point(4, -2.9999999999999996))
def test_rotate3(self): a = Point(1, 1) rotated_a = Point.rotate(a, 90) self.assertEqual(rotated_a, Point(-0.9999999999999999, 1))
def test_rotate2(self): a = Point(0, 4) rotated_a = Point.rotate(a, 90) self.assertEqual(rotated_a, Point(-4, 2.4492935982947064e-16))
def test_rotate(self): a = Point(3, 4) rotated_a = Point.rotate(a, 90) self.assertEqual(rotated_a, Point(-4, 3.0000000000000004))