Exemplo n.º 1
0
def test_points_in_poly():
    fence = [
        (50.863862, 4.678861),
        (50.863613, 4.678992),
        (50.863613, 4.678625),
        (50.863809, 4.678590),
        (50.863862, 4.678861),
    ]
    assert Polygonal.points_in_poly(Polygonal.random_coordinates((50.863743, 4.678677), 0.000110, 200), fence) == False
Exemplo n.º 2
0
def test_random_coordinate_3d():
    r = 1

    x = "x <- c("
    y = "y <- c("
    z = "z <- c("

    for i in range(1, 2000):
        p = Polygonal.random_coordinate_3d(r)
        x += str(p[0]) + ",\n"
        y += str(p[1]) + ",\n"
        z += str(p[2]) + ",\n"

    x = x[0 : len(x) - 2] + ");"
    y = y[0 : len(y) - 2] + ");"
    z = z[0 : len(y) - 2] + ");"

    graph = "par(pty='s');plot3d(x,y,z,pch='.');"

    f = open("sphere.r", "w")
    f.write(x)
    f.write(y)
    f.write(z)
    f.write(graph)
    f.close()
Exemplo n.º 3
0
def test_point_in_poly():
    pointX = 46.27007
    pointY = 5.188
    fence = [
        (46.270088180220725, 5.184173583984375),
        (46.322274857040256, 5.33111572265625),
        (46.323223245368716, 5.42449951171875),
        (46.283376780187226, 5.447845458984375),
        (46.249199583637726, 5.384674072265625),
    ]

    assert Polygonal.point_in_poly(pointX, pointY, fence) == True
Exemplo n.º 4
0
def test_bla():
    center = (50.863862, 4.678861)
    r = 0.000001
    n = 400
    points = Polygonal.random_coordinates(center, r, n)
    x_vector = "x <- c("
    y_vector = "y <- c("
    for x, y in points:
        x_vector += str(x) + ",\n"
        y_vector += str(y) + ",\n"

    print x_vector
    print y_vector
Exemplo n.º 5
0
    def run(self):
        """Executes the geo-fencing behaviour, returning a message either (halt, do_nothing)."""

        if self.vehicle.mode.name != "BRAKE" and self.vehicle.mode.name != "ALT_HOLD" and self.vehicle.mode.name != "LAND" and self.vehicle.mode.name != "RTL":
            gps_precision_in_decimal_degrees = Polygonal.centimetersToDecimalDegrees(self.vehicle.gps_0.eph)
            probable_drone_locations = Polygonal.random_coordinates((self.vehicle.location.lat, self.vehicle.location.lon), gps_precision_in_decimal_degrees, self.precision)

            # Adaptive fence, predicts the location of the drone according to its velocity, after 1 second
            if self.adaptive_fence:
                def add_velocity(x): return (x[0] + self.vehicle.velocity[0], x[1] + self.vehicle.velocity[1])
                probable_drone_locations = map(add_velocity, probable_drone_locations)

            if Polygonal.points_in_poly(probable_drone_locations, self.fence) is False:
                print "Broke circular fence."
                print self.vehicle.location
                print gps_precision_in_decimal_degrees

                return SafeBehaviour.SafeBehaviour.halt

            if self.vehicle.location.alt >= self.maximum_altitude  or self.vehicle.location.alt <= self.minimum_altitude:
                print "Broke altitude geo-fence."
                print self.vehicle.location
                print gps_precision_in_decimal_degrees

                return SafeBehaviour.SafeBehaviour.halt

        return SafeBehaviour.SafeBehaviour.do_nothing


# class BrakeCommand:
#     def __call__(self):
#         self.vehicle.mode = VehicleMode("BRAKE")
#         self.vehicle.flush()
#
#
# class NullCommand:
#     def __call__(self):
#         pass
Exemplo n.º 6
0
def test_random_coordinate():
    r = 1

    x = "x <- c("
    y = "y <- c("

    for i in range(1, 2000):
        p = Polygonal.random_coordinate(r)
        x += str(p[0]) + ",\n"
        y += str(p[1]) + ",\n"

    x = x[0 : len(x) - 2] + ");"
    y = y[0 : len(y) - 2] + ");"

    f = open("circle.txt", "w")
    f.write(x)
    f.write(y)
    f.close()
Exemplo n.º 7
0
def test_from_flight1():
    lat = 50.863831
    lon = 4.6788333
    assert Polygonal.point_in_poly(lat, lon, fence) == True
Exemplo n.º 8
0
def test_cm_to_dd_big1():
    cm = 111.32
    assert abs(0.00001 - Polygonal.centimetersToDecimalDegrees(cm)) < 0.0000001
Exemplo n.º 9
0
def test_point_outside():
    pointX = 50.863777
    pointY = 4.679216

    assert Polygonal.point_in_poly(pointX, pointY, fence) == False