get_patch_coords(lower_bound_x: float, lower_bound_y: float, side_length: float, total_patches: int, position: DronePosition) (int, int):ΒΆ

This function retrieves the patch coordinates of the current position of a drone.

Args:
  • lower_bound_x: The x-coordinate of the lower bound of the working field.

  • lower_bound_y: The y-coordinate of the lower bound of the working field.

  • side_length: The side length of the working field.

  • total_patches: The total number of patches in the working field.

  • position: A models.DronePosition object that represents the current position of the drone.

Returns:

A tuple of two integers, representing the x and y patch coordinates of the drone.

Example:

>>> from models.droneposition import DronePosition
>>> from utils.get_patch_coords import get_patch_coords
>>>
>>> lower_bound_x = 0.0
>>> lower_bound_y = 0.0
>>> side_length = 1000.0
>>> total_patches = 100
>>> position = DronePosition(latitude_deg=50.0, longitude_deg=0.0)
>>>
>>> patch_coords = get_patch_coords(lower_bound_x, lower_bound_y, side_length, total_patches, position)
>>>
>>> assert patch_coords == (5, 0)
import math

from models.droneposition import DronePosition, deg_to_m

def get_patch_coords(lower_bound_x: float,
                 lower_bound_y: float,
                 side_length: float,
                 total_patches: int,
                 position: DronePosition) -> (int, int):

    pos_x = position.latitude_deg
    pos_y = position.longitude_deg

    pos_x_m = deg_to_m(pos_x)
    pos_y_m = deg_to_m(pos_y)

    patch_length = math.ceil(side_length/total_patches)

    x_index = math.floor((pos_x_m - lower_bound_x) / patch_length)
    y_index = math.floor((pos_y_m - lower_bound_y) / patch_length)

    return (x_index, y_index)