I have a course project where I need to write a python algorithm to do the following steps:
1- Take the camera angle, flyings height and sped for the user.
2- Take x and y (represents longitude and altitude) from the user.
3- Calculate the area of the rectangle the drone needs to scan.
4- Divide the area into columns based on the camera angle.
5- Make the drone start from the middle of the first column from top then goes to bottom, then moves half of the next column's width and goes from bottom to top. the repeat till the whole area covered.
6- calculate distance then flying time.
The first 4 steps are straight forward and i added them to clarify the task details.
The algorithm required in the 5th step and then how to calculate the flying time is what I need help at.
I'm new to algorithm writing and coding in python in general, can anyone help on how I can write the algorithm required in step 5
I added the code I wrote to getting the total distance. I keep getting the distance = 0. plus I don't think the distance of the path is correctly calculated (please see the attached screenshot to shows the path)
def distance(height, angle, speed, x1, y1, x2, y2):
xc = (x1 + x2)/2
yc = (y1 + y2)/2
xd = (x1 - x2)/2
yd = (y1 - y2)/2
#Third corner
x3 = xc - yd
y3 = yc + xd
#Fourth corner
x4 = xc + yd
y4 = yc - xd
#width and heigth of the rectangle
width = x2 - x1
length= y2 - y1
#calculating a single column width
column_w = (math.sin(angle/2) * height) * 2
total_columns = int(width / column_w)
total_distance= 0
for i in range(total_columns):
total_distance = total_distance + length
if(i % 2 == 0):
print("drone movement: down, right, up")
else:
print("drone movement: up, right, down")
print(total_distance)
print(legnth)
#To get the inputs from the user
height = int(input("Enter height:"))
angle = int(input("Enter angle:"))
speed = int(input("Enter speed:"))
x1 = int(input("Enter x1:"))
y1 = int(input("Enter y1:"))
x2 = int(input("Enter x2:"))
y2 = int(input("Enter y2:"))
distance(height, angle, speed, x1, y1, x2, y2)