def shell_will_hit(self, shell, target, factor=1): """ Returns True if shell will hit rectangular object """ b = shell.angle e = Vector(1, 0) q = e.rotate(b) center = Vector(target.x - shell.x, target.y - shell.y) if center.scalar_product(q) < 0: return False a = target.angle c1 = center + Vector(target.width / 2 * factor, target.height / 2 * factor).rotate(a) c2 = center + Vector(-target.width / 2 * factor, target.height / 2 * factor).rotate(a) c3 = center + Vector(-target.width / 2 * factor, -target.height / 2 * factor).rotate(a) c4 = center + Vector(target.width / 2 * factor, -target.height / 2 * factor).rotate(a) if sign(c1.cross_product(q)) == sign(q.cross_product(c3)): #print("TEST", c1, c2, c3, c4, q) return True if sign(c2.cross_product(q)) == sign(q.cross_product(c4)): #print("TEST", c1, c2, c3, c4, q) return True return False
def shell_will_hit(self, shell, target, factor=1): """ Returns True if shell will hit rectangular object """ b = shell.angle e = Vector(1, 0) q = e.rotate(b) center = Vector(target.x - shell.x, target.y - shell.y) if center.scalar_product(q) < 0: return False a = target.angle c1 = center + Vector(target.width/2 * factor, target.height/2 * factor).rotate(a) c2 = center + Vector(- target.width/2 * factor, target.height/2 * factor).rotate(a) c3 = center + Vector(- target.width/2 * factor, - target.height/2 * factor).rotate(a) c4 = center + Vector(target.width/2 * factor, - target.height/2 * factor).rotate(a) if sign(c1.cross_product(q)) == sign(q.cross_product(c3)): #print("TEST", c1, c2, c3, c4, q) return True if sign(c2.cross_product(q)) == sign(q.cross_product(c4)): #print("TEST", c1, c2, c3, c4, q) return True return False
def vector_is_intersecting_object(self, p, d, target, factor=1): center = Vector(target.x - p.x, target.y - p.y) if center.scalar_product(d) < 0: return False a = target.angle w, h = target.width / 2 * factor, target.height / 2 * factor c1 = center + Vector(w, h).rotate(a) c2 = center + Vector(-w, h).rotate(a) c3 = center + Vector(-w, -h).rotate(a) c4 = center + Vector(w, -h).rotate(a) if sign(c1.cross_product(d)) == sign(d.cross_product(c3)): return True if sign(c2.cross_product(d)) == sign(d.cross_product(c4)): return True return False
def vector_is_intersecting_object(self, p, d, target, factor=1): center = Vector(target.x - p.x, target.y - p.y) if center.scalar_product(d) < 0: return False a = target.angle w, h = target.width/2 * factor, target.height/2 * factor c1 = center + Vector(w ,h).rotate(a) c2 = center + Vector(- w, h).rotate(a) c3 = center + Vector(- w, - h).rotate(a) c4 = center + Vector(w, - h).rotate(a) if sign(c1.cross_product(d)) == sign(d.cross_product(c3)): return True if sign(c2.cross_product(d)) == sign(d.cross_product(c4)): return True return False