0
0
Drone Programmingprogramming~20 mins

Waypoint radius and acceptance in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Waypoint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Waypoint acceptance with radius check
What is the output of this code that checks if a drone has reached a waypoint within a given radius?
Drone Programming
def has_reached_waypoint(drone_pos, waypoint_pos, radius):
    dx = drone_pos[0] - waypoint_pos[0]
    dy = drone_pos[1] - waypoint_pos[1]
    distance_squared = dx*dx + dy*dy
    return distance_squared <= radius*radius

print(has_reached_waypoint((10, 10), (13, 14), 5))
ATypeError
BFalse
CSyntaxError
DTrue
Attempts:
2 left
💡 Hint
Remember to compare squared distances to avoid costly square root calculations.
Predict Output
intermediate
2:00remaining
Effect of waypoint radius on acceptance
Given this code, what will be the output when the drone is exactly on the edge of the acceptance radius?
Drone Programming
def check_acceptance(drone_pos, waypoint_pos, radius):
    from math import sqrt
    distance = sqrt((drone_pos[0] - waypoint_pos[0])**2 + (drone_pos[1] - waypoint_pos[1])**2)
    return distance < radius

print(check_acceptance((0, 0), (3, 4), 5))
ATrue
BSyntaxError
CFalse
DTypeError
Attempts:
2 left
💡 Hint
Check the comparison operator used for acceptance.
🔧 Debug
advanced
2:00remaining
Identify the error in waypoint acceptance logic
This code is supposed to return True if the drone is within the radius of the waypoint. What error will it raise or what is the output?
Drone Programming
def is_within_radius(drone, waypoint, radius):
    distance = ((drone.x - waypoint.x)**2 + (drone.y - waypoint.y)**2)**0.5
    if distance <= radius:
        return True
    else:
        return False

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

print(is_within_radius(Point(1,2), Point(4,6), 5))
ASyntaxError
BFalse
CTrue
DAttributeError
Attempts:
2 left
💡 Hint
Check the if-else syntax carefully.
Predict Output
advanced
2:00remaining
Waypoint acceptance with 3D coordinates
What is the output of this code that checks if a drone is within a 3D waypoint radius?
Drone Programming
def within_radius_3d(drone_pos, waypoint_pos, radius):
    dx = drone_pos[0] - waypoint_pos[0]
    dy = drone_pos[1] - waypoint_pos[1]
    dz = drone_pos[2] - waypoint_pos[2]
    dist_sq = dx*dx + dy*dy + dz*dz
    return dist_sq <= radius*radius

print(within_radius_3d((1,2,3), (4,6,7), 6))
AFalse
BTrue
CIndexError
DTypeError
Attempts:
2 left
💡 Hint
Calculate squared distance in 3D and compare with squared radius.
Predict Output
expert
2:00remaining
Dynamic waypoint acceptance with variable radius
What is the output of this code that dynamically adjusts acceptance radius based on drone speed?
Drone Programming
def dynamic_acceptance(drone_pos, waypoint_pos, speed):
    base_radius = 5
    radius = base_radius + speed * 0.5
    dx = drone_pos[0] - waypoint_pos[0]
    dy = drone_pos[1] - waypoint_pos[1]
    dist_sq = dx*dx + dy*dy
    return dist_sq <= radius*radius

print(dynamic_acceptance((0,0), (6,8), 4))
ATypeError
BFalse
CNameError
DTrue
Attempts:
2 left
💡 Hint
Calculate radius including speed factor and compare squared distances.