从一个角度和一定距离的python寻找点

发布于 2025-02-10 17:44:27 字数 372 浏览 3 评论 0原文

我想在下面找到红点计数。使用Python。我该怎么做?使用给定的角度和根据placemark的距离。

每个点都有坐标(纬度,经度)。 Placemark还具有坐标。

来回示例,您可以使用角度85 dgress,其BeamWitDH可以获取50度。

给定区域中有许多红点。我有一些局限性(角度和距离)。我如何计算红点?

br,

在此处输入图像描述“

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,

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰◇生如夏花灿烂 2025-02-17 17:44:27

您的问题相对含糊,因此我要假设这是一个圆圈。

好吧,使用一些数学,我们可以弄清楚如何获得距离,d和角度,theta,基于x和y坐标的坐标。

我们知道:

x^2 + y^2 = d^2

tan(theta)= y/x

为此背后的实际数学角度theta,斜边长度D,水平长度X和垂直长度y。

解决thetad

d = sqrt(x^2 + y^2)

theta = theta = arctan(y/x)

我们的算法将列入一个元组列表(表示要点),并查看每个点的角度是否在一定范围内。此外,我们将检查每个点的距离是否小于我们的极限。如果满足这两种情况,那么我们将增加总数。

现在我们知道如何根据距离和角度找到我们的坐标,我们可以轻松地发挥我们的功能:

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

样本:

points = [(1,1),(2,3),(3,5),(4,6)]
print(countPoints(4,0,1.2,points))

输出:

2

前两个点在0和1.2弧度内的角度和小于4的距离。

请注意:为此功能,我们假设angle1&lt; Angle2,如果Angle1下降到水平轴以下,则为负。如果您的输入的Angle1为正,但在水平轴以下,则只需将其乘以-1,然后将其输入到函数中即可。

我希望这有所帮助!请让我知道您是否需要进一步的帮助或澄清!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文