I want to find red points count below picture. Using python. How can I do that? Using given angle, and distance according to placemark..
Every point has coordinate(latitude,longitude). Placemark also has coordinate.
Fro example, You can use angle 85 degress and its beamwitdh can be taken 50 degress.
there are many red dots in given area. I have some limitations (angle and distance). How can I count red dots?
BR,
Your question is relatively vague so for the time being I am going to assume that this is a circle.
Well, using some math, we can figure out how to get the distance, d, and angle, theta, coordinates based off of the x and y coordinates.
We know:
x^2 + y^2 = d^2
tan(theta) = y/x
For the actual math behind this, you can draw a right triangle with angle theta, hypotenuse length d, horizontal length x, and vertical length y.
Solving for theta
and d
:
d = sqrt(x^2 + y^2)
theta = arctan(y/x)
Our algorithm will be taking in a list of tuples (to represent points), and seeing if the angle each point makes is within a certain range. Additionally, we will check if the distance each point makes is less than our limit. If both of these conditions are met, then we will increase our total.
Now that we know how to find our coordinates based on the distance and angle, we can easily make our function:
import math
def countPoints(maxDist, angle1, angle2, points):
tot = 0
for (x,y) in points:
theta = math.atan(y/x)
dist = math.sqrt(x ** 2 + y ** 2)
if theta > angle1 and theta < angle2:
if dist < maxDist:
tot += 1
return tot
Sample:
points = [(1,1),(2,3),(3,5),(4,6)]
print(countPoints(4,0,1.2,points))
Output:
2
The first two points have an angle within 0 and 1.2 radians and a distance less than 4.
Note: For this function, we are assuming angle1 < angle2
, and that if angle1
dips below the horizontal axis, it will be negative. If your input has angle1
as positive, but is below the horizontal axis, just multiply it by -1
before inputting it into the function.
I hope this helped! Please let me know if you need any further help or clarification!