I am trying to find the maximum range of a directional antenna whose beamwidth can be varied. The goal is to understand if a particular (x,y) user lies within the antenna. The distance between the transmitter and the user(x,y) can be calculated using the distance formulae.
I have attached my code for your reference. Here I have assumed Dmax
to be 29, although that is the one that needs to be found out.
count = np.zeros(24)
def checkPoint(Dmax, x, y, percent, startAngle,index):
# calculate endAngle
endAngle = 360 / percent + startAngle
# Calculate polar co-ordinates
polarradius = math.sqrt(x * x + y * y)
if (x!=0 and y!=0):
Angle = math.atan(y / x)
degrees = math.degrees(Angle)
if (x==0):
degrees=90
elif (x==0 and y<0):
degrees=270
if (x>=0 and y<0):
degrees=360+degrees;
elif (x<0 and y<0):
degrees=180-degrees
elif (x<0 and y>0):
degrees=180+degrees;
print(degrees)
# Check whether polarradius is less
# then the maximum range
# Angle is between startAngle and
# endAngle or not
if (degrees >= startAngle and degrees <= endAngle
and polardistance < Dmax):
print("Point (", x, ",", y, ") "
"exist in the circle sector",i)
count[i]+=1
else:
print("Point (", x, ",", y, ") "
"does not exist in the circle sector",i)
Driver code
for i in range(0,50):
x=(int(random.randint(-29,29)))
y= (int(random.randint(-29,29)))
Dmax = 29
percent, startAngle = 24, 0
for i in range(0,24):
checkPoint(Dmax, x, y, percent, startAngle,i)
startAngle= startAngle+ 15
print(startAngle)
print(count)
max_value = np.max(count)
print(max_value)
max_index = np.where(count == max_value)
print(max_index)