0
0
Drone Programmingprogramming~20 mins

Setting geofence boundaries in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Geofence Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of geofence boundary check
What is the output of this code that checks if a drone is inside a rectangular geofence boundary?
Drone Programming
geofence = {'min_lat': 10.0, 'max_lat': 20.0, 'min_lon': 30.0, 'max_lon': 40.0}
drone_position = {'lat': 15.0, 'lon': 35.0}
inside = (geofence['min_lat'] <= drone_position['lat'] <= geofence['max_lat']) and (geofence['min_lon'] <= drone_position['lon'] <= geofence['max_lon'])
print('Inside geofence' if inside else 'Outside geofence')
ASyntaxError
BOutside geofence
CInside geofence
DKeyError
Attempts:
2 left
💡 Hint
Check if the drone's latitude and longitude are within the min and max values of the geofence.
🧠 Conceptual
intermediate
1:00remaining
Understanding geofence polygon boundaries
Which data structure is best to represent a polygon geofence boundary for a drone?
AA string describing the area name
BA single latitude and longitude point representing the center
CA dictionary with min and max latitude only
DA list of latitude and longitude coordinate pairs defining the polygon vertices
Attempts:
2 left
💡 Hint
A polygon needs multiple points to define its shape.
🔧 Debug
advanced
1:30remaining
Fix the geofence boundary check error
This code is supposed to check if a drone is inside a geofence but raises an error. What is the error?
Drone Programming
geofence = {'min_lat': 10.0, 'max_lat': 20.0, 'min_lon': 30.0, 'max_lon': 40.0}
drone_position = {'lat': 25.0, 'lon': 35.0}
inside = (geofence['min_lat'] <= drone_position['lat'] <= geofence['max_lat']) and (geofence['min_lon'] <= drone_position['lon'] <= geofence['max_lon'])
print('Inside geofence' if inside else 'Outside geofence')
ASyntaxError due to missing colon
BNo error; output is 'Outside geofence'
CTypeError due to comparing string with float
DKeyError because 'lat' key is missing
Attempts:
2 left
💡 Hint
Check the drone's latitude value and the geofence limits.
📝 Syntax
advanced
1:00remaining
Identify the syntax error in geofence code
Which option contains a syntax error in defining a geofence dictionary?
Ageofence = {'min_lat': 10.0, 'max_lat': 20.0, 'min_lon': 30.0, 'max_lon' 40.0}
Bgeofence = {'min_lat': 10.0, 'max_lat': 20.0, 'min_lon': 30.0, 'max_lon': 40.0}
Cgeofence = dict(min_lat=10.0, max_lat=20.0, min_lon=30.0, max_lon=40.0)
D}0.04 :'nol_xam' ,0.03 :'nol_nim' ,0.02 :'tal_xam' ,0.01 :'tal_nim'{ = ecnefoeg
Attempts:
2 left
💡 Hint
Look for missing punctuation in dictionary syntax.
🚀 Application
expert
2:30remaining
Calculate if drone is inside a polygon geofence
Given a polygon geofence defined by vertices and a drone position, which option correctly determines if the drone is inside the polygon using the ray casting algorithm?
Drone Programming
def is_inside_polygon(point, polygon):
    x, y = point
    inside = False
    n = len(polygon)
    p1x, p1y = polygon[0]
    for i in range(n + 1):
        p2x, p2y = polygon[i % n]
        if y > min(p1y, p2y):
            if y <= max(p1y, p2y):
                if x <= max(p1x, p2x):
                    if p1y != p2y:
                        xinters = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x
                    if p1x == p2x or x <= xinters:
                        inside = not inside
        p1x, p1y = p2x, p2y
    return inside

polygon = [(0,0), (0,10), (10,10), (10,0)]
drone = (5,5)
print(is_inside_polygon(drone, polygon))
ATrue
BFalse
CSyntaxError
DIndexError
Attempts:
2 left
💡 Hint
The drone is inside the square polygon defined by the vertices.