Why is geofencing an important feature in drone programming?
Think about safety and legal restrictions when flying drones.
Geofencing creates virtual boundaries that drones cannot cross, helping to keep them away from restricted zones like airports or private properties, ensuring safety and compliance with laws.
What is the output of this Python function that checks if a drone is inside a geofence?
def is_inside_geofence(x, y, fence): # fence is a dict with 'xmin', 'xmax', 'ymin', 'ymax' return fence['xmin'] <= x <= fence['xmax'] and fence['ymin'] <= y <= fence['ymax'] fence = {'xmin': 0, 'xmax': 10, 'ymin': 0, 'ymax': 10} print(is_inside_geofence(5, 5, fence)) print(is_inside_geofence(15, 5, fence))
Check if the point (x,y) lies within the rectangle defined by fence boundaries.
The point (5,5) lies inside the fence boundaries (0 to 10), so it returns True. The point (15,5) is outside the xmax boundary, so it returns False.
What error will this code produce when checking geofence violation?
def alert_violation(position, fence): if position['x'] < fence['xmin'] or position['x'] > fence['xmax'] or position['y'] < fence['ymin'] or position['y'] > fence['ymax']: print("Warning: Geofence violated!") alert_violation({'x': 12, 'y': 5}, {'xmin': 0, 'xmax': 10, 'ymin': 0, 'ymax': 10})
Check the syntax of the if statement carefully.
The if statement is missing a colon at the end, which causes a SyntaxError.
Which option correctly defines a geofence polygon as a list of coordinate tuples in Python?
Remember how lists and tuples are defined in Python.
Option D correctly uses a list of tuples with proper brackets and commas. Option D has a missing closing bracket, Option D uses a set which is unordered, and D uses semicolons which are invalid separators.
Given this code that tracks drone positions and counts geofence violations, what is the final value of violations?
fence = {'xmin': 0, 'xmax': 10, 'ymin': 0, 'ymax': 10}
positions = [{'x': 5, 'y': 5}, {'x': 11, 'y': 5}, {'x': 7, 'y': 12}, {'x': 3, 'y': 3}]
violations = 0
for pos in positions:
if pos['x'] < fence['xmin'] or pos['x'] > fence['xmax'] or pos['y'] < fence['ymin'] or pos['y'] > fence['ymax']:
violations += 1
print(violations)Count how many positions fall outside the fence boundaries.
Positions at (11,5) and (7,12) are outside the fence, so violations count is 2.