Exemple #1
0
    def test_central_crash(self):
        # base of triangle2 (from orig to dest)
        o = KineticVertex()
        o.origin = (0., 0.)
        o.velocity = (sqrt(2), sqrt(2))

        d = KineticVertex()
        d.origin = (10., 0.)
        d.velocity = (-sqrt(2), -sqrt(2))

        # vertex supposed to crash into base (the apex)
        a = KineticVertex()
        a.origin = (5, 5)
        a.velocity = (0, -sqrt(2))
        # edge collapse times
        times = []
        time = collapse_time_edge(o, d)
        times.append(time)
        time = collapse_time_edge(d, a)
        times.append(time)
        time = collapse_time_edge(a, o)
        times.append(time)
        # area collapse time
        area = area_collapse_times(o, d, a)
        times.extend(area)
        # vertex crash time
        time = vertex_crash_time(o, d, a)
        times.append(time)
        # filter None out of the times and see what is there...
        times = get_unique_times(times)
        show_all_times(times, o, d, a)
Exemple #2
0
    def test_crash(self):
        # base of triangle (from orig to dest)
        o = KineticVertex()
        o.origin = (0., 0.)
        o.velocity = (0., 1.)

        d = KineticVertex()
        d.origin = (10., 0.)
        d.velocity = (0, 1.)

        # vertex supposed to crash into base (the apex)
        a = KineticVertex()
        a.origin = (5, 5)
        a.velocity = (0., -1.)
        times = []
        # vertex crash time
        time = vertex_crash_time(o, d, a)
        times.append(time)
        # edge collapse times
        time = collapse_time_edge(o, d)
        times.append(time)
        time = collapse_time_edge(d, a)
        times.append(time)
        time = collapse_time_edge(a, o)
        times.append(time)
        # area collapse time
        coeff = area_collapse_time_coeff(o, d, a)
        time = solve_quadratic(coeff[0], coeff[1], coeff[2])
        times.extend(time)
        times = get_unique_times(times)
        show_all_times(times, o, d, a)
Exemple #3
0
    def test_perpendicular2_crash(self):
        # base of triangle2 (from orig to dest)
        o = KineticVertex()
        o.origin = (0., 0.)
        o.velocity = (0., 1.)

        d = KineticVertex()
        d.origin = (10., 0.)
        d.velocity = (0, 1.)

        # vertex supposed to crash into base (the apex)
        a = KineticVertex()
        a.origin = (5, 5)
        a.velocity = (1, 0)
        # edge collapse times
        times = []
        time = collapse_time_edge(o, d)
        times.append(time)
        time = collapse_time_edge(d, a)
        times.append(time)
        time = collapse_time_edge(a, o)
        times.append(time)
        # area collapse time
        area = area_collapse_times(o, d, a)
        times.extend(area)
        # vertex crash time
        time = vertex_crash_time(o, d, a)
        times.append(time)
        #
        times = get_unique_times(times)
        show_all_times(times, o, d, a)
Exemple #4
0
    def test_0tri(self):
        t = self.triangles[139643876356560]
        print t.str_at(0)
        print t.neighbours
        evt = compute_collapse_time(t, now=0)
        print t.str_at(evt.time)
        pos = [v.position_at(evt.time) for v in t.vertices]
        for v in t.vertices:
            print v.origin
            print v.velocity
        times = []
        #         for side in range(3):
        #             i, j = cw(side), ccw(side)
        #             v1, v2 = t.vertices[i], t.vertices[j]
        #             times.append((collapse_time_edge(v1, v2), side))
        side = 0
        i, j = cw(side), ccw(side)
        v1, v2 = t.vertices[i], t.vertices[j]
        time = collapse_time_edge(v1, v2)
        times.append(time)
        side = 2
        i, j = cw(side), ccw(side)
        v1, v2 = t.vertices[i], t.vertices[j]
        with open("/tmp/cpa.csv", "w") as fh:
            for i, inc in enumerate(range(100, 150), start=1):
                val = inc / 1000.
                v1.position_at(val)
                v2.position_at(val)
                print >> fh, val, ";", sqrt(v1.distance2_at(v2, val))
        time = collapse_time_edge(v1, v2)
        times.append(time)
        for time in times:
            print "", time
        from datetime import datetime, timedelta

        with open("/tmp/kinetic.wkt", "w") as fh:
            fh.write("start;end;wkt\n")
            prev = datetime(2015, 1, 1)
            #prev = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
            for inc in range(100, 150):
                val = inc / 1000.
                cur = prev
                fh.write("{};{};{}\n".format(prev, cur, t.str_at(val)))
                prev = cur + timedelta(days=1)
        print "times", times
        print "orientation", orient2d(*pos)
        assert evt is not None
        print evt
Exemple #5
0
def compute_all_collapse_times(o, d, a):
    # edge collapse times
    times = []
    time = collapse_time_edge(o, d)
    times.append(time)
    time = collapse_time_edge(d, a)
    times.append(time)
    time = collapse_time_edge(a, o)
    times.append(time)
    # area collapse times
    area = area_collapse_times(o, d, a)
    times.extend(area)
    # vertex crash time of the apex into the segment, orig -> dest
    time = vertex_crash_time(o, d, a)
    times.append(time)
    return times
Exemple #6
0
 def test_parallel_follower(self):
     """one vertex follows the other vertex on its track"""
     u = KineticVertex()
     u.origin = (0., 0.)
     u.velocity = (0., 1.)
     v = KineticVertex()
     v.origin = (0., -10.)
     v.velocity = (0., 1.)
     time = collapse_time_edge(u, v)
     assert time is None
Exemple #7
0
 def test_parallel_overlap(self):
     """2 vertices having the exact same track"""
     u = KineticVertex()
     u.origin = (0., 0.)
     u.velocity = (0., 1.)
     v = KineticVertex()
     v.origin = (0., 0.)
     v.velocity = (0., 1.)
     time = collapse_time_edge(u, v)
     assert time is None
Exemple #8
0
    def test_parallel(self):
        """2 vertices moving in parallel"""
        u = KineticVertex()
        u.origin = (0., 0.)
        u.velocity = (0., 1.)

        v = KineticVertex()
        v.origin = (10., 0.)
        v.velocity = (0., 1.)
        time = collapse_time_edge(u, v)
        assert time is None
Exemple #9
0
    def test_bump(self):
        """2 vertices that bump into each other half way"""
        u = KineticVertex()
        u.origin = (0., 0.)
        u.velocity = (1., 1.)

        v = KineticVertex()
        v.origin = (10., 10.)
        v.velocity = (-1., -1.)
        time = collapse_time_edge(u, v)
        assert time is not None
        dist = u.distance2_at(v, time)
        assert near_zero(dist)
Exemple #10
0
    def test_equilateral_outwards(self):
        #         k = KineticTriangle()
        V = []
        v = KineticVertex()
        v.origin = (0.0, 0.0)
        v.velocity = (-2.1889010593167346, -1.0)
        V.append(v)
        v = KineticVertex()
        v.origin = (3.0, 0.0)
        v.velocity = (2.1889010593167346, -1.0)
        V.append(v)
        v = KineticVertex()
        v.origin = (1.5, 1.7320508075688772)
        v.velocity = (0.0, 1.5275252316519463)
        V.append(v)
        o, d, a = V
        print o, d, a
        #         k.vertices = V

        # edge collapse times
        times = []
        time = collapse_time_edge(o, d)
        times.append(time)
        time = collapse_time_edge(d, a)
        times.append(time)
        time = collapse_time_edge(a, o)
        times.append(time)
        # area collapse times
        area = area_collapse_times(o, d, a)
        times.extend(area)
        # vertex crash time
        time = vertex_crash_time(o, d, a)
        times.append(time)
        #
        print times
        times = get_unique_times(times)
        show_all_times(times, o, d, a)
        self.assertRaises(ValueError, find_ge, times, 0)
Exemple #11
0
    def test_crossing(self):
        """2 vertices crossing each other"""
        u = KineticVertex()
        u.origin = (0., 0.)
        u.velocity = (1., 1.)

        v = KineticVertex()
        v.origin = (10., 0.)
        v.velocity = (-1., 1.)
        time = collapse_time_edge(u, v)
        #         with open("/tmp/cpa.csv","w") as fh:
        #             for i, inc in enumerate(range(100, 150), start=1):
        #                 val = inc / 1000.
        #                 u.position_at(val)
        #                 v.position_at(val)
        #                 print >>fh, val,";", sqrt(u.distance2_at(v, val))
        dist = u.distance2_at(v, time)
        assert near_zero(dist)