Beispiel #1
0
def test_polyline_get_Iz():
    pl = PolyLine([(0, 3), (10, 3), (10, 0), (0, 0)], copy_data=True)
    for angle in np.random.uniform(-180, 180, 1000):
        pl1 = pl.add_vec(Vec2(10, 20))
        plt = pl1.transform(Mat2.from_angle(angle, True))
        cm = plt.get_center_mass()
        assert plt.get_Iz(cm) == approx((10**2 + 3**2) / 12)
Beispiel #2
0
def test_constructor8():
    from math import sin, cos, pi
    for angle in np.random.uniform(-720, 720, 1000):
        angle *= pi / 180
        m = Mat2.from_angle(angle)
        assert m is not None
        assert m.m11 == approx(cos(angle))
        assert m.m12 == approx(sin(angle))
        assert m.m21 == approx(-sin(angle))
        assert m.m22 == approx(cos(angle))
Beispiel #3
0
def test_mul2():
    for angle, x, y in np.random.uniform(-180, 180, (1000, 3)):
        m = Mat2.from_angle(angle, 1)
        v = Vec2(x, y).norm()
        v1 = m * v
        assert v.angle_to(v1, 1) == approx(-angle)
        v2 = m._1 * v1
        assert v2 == v
        v3 = m._1 * v
        assert v.angle_to(v3, 1) == approx(angle)
Beispiel #4
0
def test_polyline_area4():
    pl = PolyLine([(1, 2), (11, 2), (10, 0), (0, 0)], copy_data=True)
    for angle in np.random.uniform(-180, 180, 1000):
        pl1 = pl.add_vec(Vec2(10, 20))
        plt = pl1.transform(Mat2.from_angle(angle, True))
        assert plt.get_area() == approx(20)
Beispiel #5
0
def test_inverse1():
    for angle in np.random.uniform(-720, 720, 1000):
        m = Mat2.from_angle(angle)
        assert m._1 == m.T
        assert m.det() == approx(1)
Beispiel #6
0
 def set_alpha(self, alpha):
     self.alpha = alpha
     self.M_rot = Mat2.from_angle(alpha, degrees=True)
     self.M_rot_1 = self.M_rot._1
Beispiel #7
0
                return res
        return {}

    def shoot(self):
        if not self.can_shoot:
            return None
        angle = np.random.normal(self.alpha, self.theta / 3)
        vel = Vec2(self.round_vel, 0).rotate(angle, degrees=True)
        self.time_last_shot = self.time
        v = 3 * vel.norm() + self.pos
        return Round(v, vel, self.dmg)


class Round(object):
    id_counter = 0

    def __init__(self, pos, vel, dmg):
        self.pos = _convert(pos).copy()
        self.vel = _convert(vel).copy()
        self.dmg = dmg
        self.id = Round.id_counter
        Round.id_counter += 1

    def get_move_segment(self, dt: float):
        return (self.pos.copy(), self.pos + dt * self.vel)


if __name__ == "__main__":
    m = Mat2.from_angle(90, True)
    print(m._1 * Vec2(1, 0))