【问题标题】:Adding points to a race circuit为赛道添加积分
【发布时间】:2021-05-25 12:14:23
【问题描述】:

我在 Python 中有 2 个带有纬度和经度坐标的数组。它们对应于电路的坐标。它的情节如下所示: Plot of the race

事实上,我需要在我的电路上设置更多点,理想情况下,我需要所有点彼此之间的距离相同。

我想这与插值有关,因为 Python 在绘制时链接点没有问题,但我找不到插值函数。

提前致谢!

【问题讨论】:

    标签: python interpolation circuit


    【解决方案1】:

    如果点对之间的距离太大,您可以在点对之间添加点。伪代码示例:

    points_array = a new empty array of points
    
    p1, p2 = two successive points
    distance_p1p2 = sqrt( (p1.x - p2.x)² + (p1.y - p2.y)²)
    
    # Add p1 to the new array of points
    points_array.push(p1)
    
    if distance_p1p2 > threshold:  # threshold = 0.00005 for example, you can define it
        # Create an intermediate point in between p1 and p2
        intermediate_point.x = (p1.x + p2.x) / 2
        intermediate_point.y = (p1.y + p2.y) / 2
        
        # Add this intermediate point to the new array of points
        points_array.push(intermediate_point)
    
    # Add p2 to the new array of points
    points_array.push(p2)
    

    这些简单的步骤可让您在彼此相距太远的 2 个点之间添加一个中间点。从一个空数组开始并在所有点之间循环,您将获得一个包含更多点的新数组(如果阈值太大,则为相同数量的点)。

    然后,您可以根据需要多次迭代并执行此算法。

    我想指出一个事实,这是基本算法,没有优化。例如,您可以分析每对点之间的距离并创建n 中间点,而不是一次创建一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      相关资源
      最近更新 更多